Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Offset wrong on refresh of page

I'm using jQuery offset function to place an absolutely positioned DIV over an anchor element.

$("#marker1").offset({ top: $("#<%= hypHowItWorks.ClientID %>").offset().top, left: $("#<%= hypHowItWorks.ClientID %>").offset().left });
$("#marker1").width( $("#<%= hypHowItWorks.ClientID %>").outerWidth() );

When the page loads up this works fine, however, if I reload the page by hitting F5, it displays the DIV slightly offset from where it shoud be. If I then go page back-forward in the browser its in the right place again!!

This is an issue with latest Chrome and Firefox, but not with IE9.

Any ideas?

Chris.

like image 701
Chris Avatar asked Jul 25 '12 12:07

Chris


1 Answers

Try it in the $(window).load event instead of $(document).ready.

I had the same problem and could fix it with that trick!

like image 99
Raphael Avatar answered Oct 29 '22 05:10

Raphael