删除 Javascript 工具提示偏移以获得更好的悬停增长效果
我正在努力完成一些事情,并将感谢所提供的任何和所有帮助!
我有一个工具提示代码,当鼠标悬停在图像上时,图像会通过 JS 出现在工具提示中并具有偏移位置。我希望工具提示中的图像没有偏移地显示,而不是偏移工具提示中悬停图像的位置,与您在此示例中看到的悬停效果完全相同。我需要工具提示的位置根本不偏移,只需正好位于图像顶部即可。我不确定如何实现这一点,因为示例代码使用 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";
}
如何使用给定的代码来完成此操作,有什么想法吗?
I'm trying to accomplish something and will appreciate any and all help provided!
I have a tooltip code that on hover of an image, the image appears in the tooltip with an offset position via JS. Instead of offsetting the position of the hovered image in the tooltip, I want the image in the tooltip be displayed with no offsets, EXACTLY like the hover effect you see in this example. I need the position of the tooltip to not be offset at all, just be exactly on top of the image. I'm not sure how to accomplish this since the example code uses css and I need it working with this tooltip in JS.
Here's the tooltip code:
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";
}
How can I accomplish this with the given code, any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当然可以将其调整得更好,但这是一个概念证明。
注意:您的图像样式应为
位置:相对
用法 (演示)
构造函数
动画 (emile.js )
测试平台:IE7+、FF2+、Safari 4+、Chrome、Opera
You sure can tweak it to be better, but here is a proof of concept.
Note: Your images' style should be
position: relative
Usage (Demo)
Constructor
Animation (emile.js)
Tested On: IE7+, FF2+, Safari 4+, Chrome, Opera