jquery - Check window size on load and on resize with condition -
i building script requires change entire functionality of script when window size gets under 783px, i've found solution
if(jquery(document).width() < "783" && myvar=="1"){ //do things screens under 783px }
but works if screen under 783px when first loaded site, want check on resize since css media queries work , gets messed up. need this:
if((document).width()<783 && myvar=="1" || onresize(document.width<783) && myvar=="1"){ //do things screens under 783px }
can me this? i've tried doing with
jquery(window).on("resize", function () { //do things under 783px }).resize();
but doesn't seems work, if has suggestion please share.
use:
function check() { if ($(document).width() < 783 && myvar === "1") { // use `===` , no quote around 783 console.log("y"); } } check(); // first-time check $(window).resize(function () { // no `on` here check(); }); // no `.resize()` needed here
demo
note: wrap whole in $(window).load()
Comments
Post a Comment