javascript - Fixed scrolling div refusing to stick in IE -


i have following code have div sticks after it's scrolled. works in modern browsers except ie (8, 9 or 10).

any quick fixes? appreciated.

<script> //turns sidebar fixed scrolling var header = document.queryselector('.stickysidebar'); var origoffsety = header.offsettop;  function onscroll(e) {   window.scrolly >= origoffsety ? header.classlist.add('sticky') :                               header.classlist.remove('sticky'); }  document.addeventlistener('scroll', onscroll); </script> 

ie 8 not support addeventlistener, must use attachevent (see: https://developer.mozilla.org/en-us/docs/web/api/eventtarget.addeventlistener#compatibility)

an example work around (modified mdn page):

if (el.addeventlistener) {   el.addeventlistener('scroll', onscroll);  } else if (el.attachevent)  {   el.attachevent('onscroll', onscroll); } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -