Disable Skrollr for mobile device ( <767px )

后端 未结 6 2079
暖寄归人
暖寄归人 2021-02-02 01:59

Firstly would like to thanks @prinzhorn for such an amazing and powerful library. My question: I have implemented a Skrollr parallax background to the header of my website but I

6条回答
  •  心在旅途
    2021-02-02 02:47

    The destroy() method does do that. You can also avoid initializing skrollr on small windows to begin with, and/or destroy skrollr if the window gets resized to be small.

    $(function () {
      // initialize skrollr if the window width is large enough
      if ($(window).width() > 767) {
        skrollr.init(yourOptions);
      }
    
      // disable skrollr if the window is resized below 768px wide
      $(window).on('resize', function () {
        if ($(window).width() <= 767) {
          skrollr.init().destroy(); // skrollr.init() returns the singleton created above
        }
      });
    });
    

    In this example, skrollr does not get re-enabled if the window gets resized to be large.

提交回复
热议问题