Disabling JavaScript on certain conditions like a media query -
i'm trying disable script run @ screen size.
<script> function init() { window.addeventlistener('scroll', function(e){ var distancey = window.pageyoffset || document.documentelement.scrolltop, shrinkon = 250, header = document.queryselector("header"); if (distancey > shrinkon) { classie.add(header,"smaller"); } else { if (classie.has(header,"smaller")) { classie.remove(header,"smaller"); } } }); } window.onload = init(); </script> i've tried wrapping code following
if($(window).width() > 1200) { // script here } and
window.addeventlistener('resize', function(){ if(window.innerwidth > 568){ // script here } }); but none of them seems work. recommendations?
Comments
Post a Comment