[javascript]
$(获取到需要弹出浮动框的元素obj).hover(function () {
//鼠标移动时
//获取到需要弹出浮动框的元素obj
divobj = document.getElementById(obj);
//获取obj的位置,left及top,IE及FF3.0以上都支持
divobjleft = divobj.getBoundingClientRect().left;
divobjtop = divobj.getBoundingClientRect().top;
//为弹出的div的left,top赋值
divobjx = divobjleft + 0 /* 弹出的div距离obj左边的距离,取实际值 */;
divobjy = divobjtop + 50 /* 弹出的div距离obj顶部的距离,取实际值 */;
// 定义弹出div
var x = "
这里是内容,也可以通过参数来传递
";
//Write into html through insertAdjacentHTML (Firefox does not support this parameter, but it is possible to make Firefox compatible with the insertAdjacentHTML attribute through compatibility code. The compatibility code is not long, just dozens of lines)
document.body.insertAdjacentHTML(" afterBegin",
function closeDiv(obj) {
var divobj = document.getElementById(obj);
divobj.parentNode.removeChild(divobj);
}
/* End remove element method*/
/* Start compatibility code to make Firefox compatible insertAdjacentHTML attribute*/
if (typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = function (where, parsedNode) {
switch (where) {
case "beforeBe gin":
this.parentNode.insertBeFore (PARSEDNODE, this);
Case "afterbegin":
this.InSerTBEFORE (PARSEDNODE, this.firstChild);
Break;
Cas E "Beforend":
This.appendchild (PARSEDNODE);
break; } else {
using using use using using use using ’s ’ through ’ s through out ‐ through ‐ ‐ ‐ ‐‐ ‐ } else }
};
HTMLElement.prototype.insertAdjacentHTML = function (where, htmlStr) {
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.create ContextualFragment(htmlStr);
this.insertAdjacentElement(where, parsedHTML);
};
HTMLElement.prototype.insertAdjacentText = function (where, txtStr) {
var parsedText = document.createTextNode(txtStr);
this.insertAdjacentElement(where , parsedText);
};
}
/* End compatibility code makes Firefox compatible with insertAdjacentHTML attribute*/