mercredi 4 mars 2015

javascript to run after browser has scrolled to url fragment

I have the following code deep within a webpage:



<div id="123">


When a user navigates to http://ift.tt/1M5jgRK the browser will automatically scroll to the div position due to the fragment "#123".


I want some javascript to run after the browser has scrolled to the div position (so I can the change the position by 111px)


The webpage also has lots of images which take a while to download, and the browser scrolls before these images are all downloaded - which is good.


So, I can't use the window.onload event as this won't run until all the images are downloaded.


The javascript I want to run after the browser has scrolled to the div is below. This works fine in Chrome but not in IE:



window.setTimeout(
function () {
var scrollTop = $(window).scrollTop();
$(window).scrollTop(scrollTop - 111);
}, 0);




Aucun commentaire:

Enregistrer un commentaire