jquery ie8scrollTop和偏移问题
我试图将一个非常简单的悬停工具提示放置在页面上一系列元素的正上方。我的定位代码在FF中完美运行,但在IE8中如果页面滚动则定位失败。我正在补偿滚动,但在 IE8 中似乎我必须将数字加倍才能正常工作。
$('.evidence_thumb').mouseenter(function() {
var position = $(this).position();
$top = ((position.top - $('#icon_tool_tip').height()) + $(window).scrollTop()) + 10;
$left = ((position.left) + $(window).scrollLeft()) - 40;
$('#icon_tool_tip').offset({ top: $top, left: $left });
});
上述代码显示的误差幅度始终恰好是scrollTop 的量。我还没有测试过水平滚动,但我认为它也会有同样的问题。
I am attempting to position a very simple hover tool tip directly above a series of elements on a page. My positioning code works perfectly in FF, but in IE8 the positioning fails if the page is scrolled. I am compensating for scroll, but in IE8 it seems I have to double the number for it to work correctly.
$('.evidence_thumb').mouseenter(function() {
var position = $(this).position();
$top = ((position.top - $('#icon_tool_tip').height()) + $(window).scrollTop()) + 10;
$left = ((position.left) + $(window).scrollLeft()) - 40;
$('#icon_tool_tip').offset({ top: $top, left: $left });
});
The margin of error in display with the above code is always exactly the amount of the scrollTop. I haven't tested with horizontal scroll, but I assume it will have the same issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会准确地称其为“已解决”,但我停止使用 jquery 偏移量,转而使用 css。我改变了:
$('#icon_tool_tip').offset({ 顶部: $top, 左侧: $left });
到:
$('#icon_tool_tip').css({ 顶部: $top, 左侧: $left });
这让我的问题消失了,但是这里发生了一些奇怪的事情,我想了解一下偏移量。
I wouldn't call this "solved" exactly, but I stopped using the jquery offset in favor of css. I changed:
$('#icon_tool_tip').offset({ top: $top, left: $left });
to:
$('#icon_tool_tip').css({ top: $top, left: $left });
It made my issue go away, but there is something odd going on here with the offset that I would have liked to understand.