0

I trie to get the result of this function :

var isLaptop = false;
function is1024up() {   
    $(window).on('load resize', function() {
        isLaptop = $(window).width() > 1024;
    });
    return isLaptop;
} 

lap = is1024up(); // I put the result of my function in a global

I would like to use the result of this function on parameter of another function

function test(lap){
    console.log(lap); //the result don't change on resize
    if (lap) {
      // my code here
    }

}

My issue is on the resize function : I can get the result on is1024up() when the page load but this result isn't uptable on resize.

Any idea ?

BrownBe
  • 977
  • 3
  • 11
  • 23

1 Answers1

0

You can't do it with return. Use the resize event to just update the variable. Use the isLaptop variable just everywhere to read the current state.

var isLaptop = false;

$(window).on('load resize', function() {
    isLaptop = $(window).width() > 1024;
});

function test() {
    console.log(isLaptop);
}
eisbehr
  • 12,243
  • 7
  • 38
  • 63