jqueryはcssの絶対位置効果を制御します.例えば、マウスをアイコン表示層に移動して関連情報を表示します.
2976 ワード
$( 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.insertAdjacentHTML("afterBegin", x);
}, function () {
// , closeDiv() div
closeDiv("description");
})
/* Sart */
function closeDiv(obj) {
var divobj = document.getElementById(obj);
divobj.parentNode.removeChild(divobj);
}
/* End */
/* Start insertAdjacentHTML */
if (typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = function (where, parsedNode) {
switch (where) {
case "beforeBegin":
this.parentNode.insertBefore(parsedNode, this);
break;
case "afterBegin":
this.insertBefore(parsedNode, this.firstChild);
break;
case "beforeEnd":
this.appendChild(parsedNode);
break;
case "afterEnd":
if (this.nextSibling) {
this.parentNode.insertBefore(parsedNode, this.nextSibling);
} else {
this.parentNode.appendChild(parsedNode);
}
break;
}
};
HTMLElement.prototype.insertAdjacentHTML = function (where, htmlStr) {
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where, parsedHTML);
};
HTMLElement.prototype.insertAdjacentText = function (where, txtStr) {
var parsedText = document.createTextNode(txtStr);
this.insertAdjacentElement(where, parsedText);
};
}
/* End insertAdjacentHTML */
転載先:https://www.cnblogs.com/smartsmile/archive/2012/08/28/6234440.html