使用Javascript动态计算弹出窗口位置 [英] Dynamically calculate the Popup window Position using Javascript
本文介绍了使用Javascript动态计算弹出窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我必须在单词mousehover上使用Div标签显示一个弹出窗口,所以我尝试了两种不同的Javascript方法来动态计算弹出窗口的位置,但不是它们工作正确的,请帮我找到解决方案:
我的方法:
Hi All,
I have to display a popup window using Div tag on a word mousehover, so i tried 2 different Javascript method to dynamically calculate the position of popup window, but non of them working properly, please help me to find the solution:
My method :
function findPosss(obj)
{
var obj2 = obj;
var curtop = 0;
var curleft = 0;
if (document.getElementById || document.all) {
do {
curleft += obj.offsetLeft-obj.scrollLeft;
curtop += obj.offsetTop-obj.scrollTop;
obj = obj.offsetParent;
obj2 = obj2.parentNode;
while (obj2!=obj) {
curleft -= obj2.scrollLeft;
curtop -= obj2.scrollTop;
obj2 = obj2.parentNode;
}
} while (obj.offsetParent)
} else if (document.layers) {
curtop += obj.y;
curleft += obj.x;
}
return [curleft,curtop];
} // end of findPos()
function getOffset( el )
{
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return [_x,_y];//{ top: _y, left: _x }
}
注意:间接你可以说我想在IE浏览器中使用Javascript播放工具提示。
任何帮助表示赞赏。
谢谢
AP
Note: Indirectly you can say i want to dssplay tooltip in IE browser using Javascript.
Any help is appreciated.
Thanks
AP
推荐答案
试试这个
http://api.jquery.com/hover/ [ ^ ]
http://stackoverflow.com/questions/3559467/description-box-on-mouseover [ ^ ]
try this
http://api.jquery.com/hover/[^]
http://stackoverflow.com/questions/3559467/description-box-on-mouseover[^]
function popupwindow(url,ti tle,w,h){
var left =(screen.width / 2) - (w / 2);
var top =(screen.height / 2) - (h / 2);
返回window.open(url,title,''toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = no, resizable = no,copyhistory = no,width =''+ w +'',height =''+ h +'',top =''+ top +'',left =''+ left);
}
function popupwindow(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, ''toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=''+w+'', height=''+h+'', top=''+top+'', left=''+left);
}
这篇关于使用Javascript动态计算弹出窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文