【发布时间】:2010-12-03 21:36:46
【问题描述】:
我正在努力完成某件事,我将不胜感激所提供的任何和所有帮助!
我有一个工具提示代码,在图像悬停时,图像会出现在工具提示中,并通过 JS 偏移位置。我不想在工具提示中偏移悬停图像的位置,而是希望工具提示中的图像显示为没有偏移,EXACTLY like the hover effect you see in this example。我需要工具提示的位置根本不偏移,正好在图像的顶部。我不知道如何实现这一点,因为示例代码使用 css,我需要它在 JS 中使用此工具提示。
这里是工具提示代码:
too = tooo = bi = an = null; document.onmousemove = document.onmouseover = toolt;
function toolt(a) {
if(bi) {
y = bi.offsetTop+bi.height-20;
x = bi.offsetLeft+bi.width-12;
} else {
y = (document.all) ? window.event.y + document.body.scrollTop : a.pageY;
x = (document.all) ? window.event.x + document.body.scrollLeft : a.pageX;
}
a = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
b = window.innerWidth ? window.innerWidth : document.body.offsetWidth;
if (too != null) {
if(too.offsetWidth+x+35-document.body.scrollLeft > b) x=document.body.scrollLeft+b-too.offsetWidth-35; too.style.left = (x+12)+"px";
if(too.offsetHeight+y+40-document.body.scrollTop > a) y=y-too.offsetHeight-30; too.style.top = (y+20)+"px"; }
}
function htoo(i) { if(too) too.style.display = "none"; if(bi) bi.style.display = an ? "block" : "none"; tooo = false;}
function stoo(i) { if(tooo) tooo.style.display = "none"; if(bi) bi.style.display = an ? "block" : "none"; too = tooo = document.getElementById(i); too.style.display = "block"; if(bi = document.getElementById(i+"b")) bi.style.display="block";
}
我怎样才能用给定的代码完成这个,有什么想法吗?
【问题讨论】:
-
你链接的页面中的JS代码你看了吗?
-
是的,我有,但我只需要删除提供的工具提示代码中的偏移量。工具提示中的 JS 对我来说太复杂了。我只想编辑上面提供的代码以显示工具提示在图像上的位置而不是偏移它。这有意义吗?
标签: javascript hover tooltip position offset