jQuery: How to detect window width on the fly?

后端 未结 4 568
栀梦
栀梦 2020-11-27 12:27

I have a scrolling element on my page (with the jScrollPane jQuery plugin). What I want to accomplish is a way to turn off the scrolling window by detecting the width of the

4条回答
  •  遥遥无期
    2020-11-27 12:50

    Put your if condition inside resize function:

    var windowsize = $(window).width();
    
    $(window).resize(function() {
      windowsize = $(window).width();
      if (windowsize > 440) {
        //if the window is greater than 440px wide then turn on jScrollPane..
          $('#pane1').jScrollPane({
             scrollbarWidth:15, 
             scrollbarMargin:52
          });
      }
    });
    

提交回复
热议问题