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
Post a Comment