开发者

jquery ie8 scrollTop and offset issue

开发者 https://www.devze.com 2023-02-22 00:26 出处:网络
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 scrol

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.to开发者_如何学Gop - $('#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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消