[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 = "
这里是内容,也可以通过参数来传递
";
//透過insertAdjacentHTML來寫入到html內(這個參數火狐不支持,但是可能透過相容程式碼讓火狐相容insertAdjacentHTML 屬性,相容程式碼不長,就幾十行)
document.body相容程式碼不長,就幾十行)
afterBegin", x);
}, function () {
//滑鼠移出時,將此div
closeDiv("description");
closeDiv("description");
}
function closeDiv(obj) {
var divobj = document.getElementById(obj);
divobj.parentNode.removeChild(divobj);代碼讓火狐相容insertAdjacentHTML 屬性*/
if (typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = function ( HTMLElement.prototype.insertAdjacentElement = function ( HTMLElement.
case "beforeBegin":
this.parentNode.insertBefore(parsedNode, this);
break;
this.insertBefore(parsedNode, this.firstChild);
this.appendChild(parsedNode);
break;
case "afterEnd":
this.parentNode.insertBefore(parsedNode, this.nextSibling);
parentNode.appendChild(parsedNode);
}
}
};
HTMLElement.prototype.insertAdjacentHTML = function (where, htmlStr) {
(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where, parsedHTML);
};
HTMLElement.prototype.insertAdjacentText = function (where this.insertAdjacentElement(where, parsedText);
};
}
/* End 相容程式碼讓火狐相容insertAdjacentHTML 屬性*/