Tom
Tom

Reputation: 1991

jquery ie8 scrollTop and offset issue

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.

Upvotes: 1

Views: 2593

Answers (1)

Tom
Tom

Reputation: 1991

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.

Upvotes: 1

Related Questions