Block change value of variable when refresh page in javascript -


i have 2 variables name first , last. when window size less 768px, want first = 1 , last = 5. , when window size greater 768px, first = 1 , last = 3. here code.

var first = 1; var last = 5; window.onresize = function(){     var w = window.innerwidth              || document.documentelement.clientwidth              || document.getelementsbytagname('body')[0].clientwidth;      if (w <= 768){         first = 1;         last = 3;     }      if (w > 768){         first = 1;         last = 5;     } }  

it's worked. when window size 600px (less 768px), press f5 (refresh), first variable = 1 , last = 5 (these values changed). want when press f5, if window less 768px, still 1 , 3. can now? me. thanks.

this how should be.

so now, have 1 function set variables per width of window. call 2 times

  1. when page loaded, should set variables (first,last) per size of window

  2. when page resized, should set variables again.

    var first = 1; var last = 5;  function setvariables() { var w = window.innerwidth          || document.documentelement.clientwidth          || document.getelementsbytagname('body')[0].clientwidth;  if (w <= 768){     first = 1;     last = 3; }  if (w > 768){     first = 1;     last = 5; } }  window.onresize = function(){ setvariables(); }   setvariables(); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -