javascript - scrolltop() doesn't work in IE9 at all -


http://jsfiddle.net/qf47a/7/

function onscroll(){     document.getelementbyid("fly").style.top=""+ $(document).scrolltop() * 5 +"px"; } 

check out... sigh

not working 1 bit in ie9... haven't tested in ie10 yet. yes, works in chrome, firefox, , every browser under sun except damned ie.

listen window's scroll event instead:

$(window).on('scroll', function() {     document.getelementbyid("fly").style.top = $(document).scrolltop() * 5 +"px"; }); 

demo


tested in latest chrome, firefox, opera 15 , ie8. seems work fine in browser, main issue ie not parse body's onscroll attribute window.onscroll property other browsers do. live test case. test case source:

<body onscroll="42;"> 

document.body.innerhtml = 'does ' + (window.onscroll ? '' : '<b>not</b> ') +      'parse body onscroll attribute window.onscroll'; 

so assigning event handler directly window.onscroll solve issue, you're using jquery .on() method preferred event binding. patches cross-browser inconsistencies , don't have worry overwriting pre-existing handlers.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -