当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - skrollr.js: Turn off or destroy skrollr at a given window width

问题描述:

I'm using skrollr.js to animate a few things on a page. I'd like to only initialize skrollr when the window viewport width is larger than a particular size, and completely remove it or destroy it when I'm below that viewport width.

For instance, when the browser window width is greater than 600px, I want skrollr to be initialized, but when the browser's window width is less than 600px, I want to turn off or destroy skrollr.

网友答案:

The destroy instance method is what you are looking for. I've been working on it on last weeks and now it looks like Prinzhorn already merged my changes on the master branch.

Hope to be helpful, cheers!

网友答案:

You can use Modernizr (and Yepnope.js) to test a given media query, then, if it returns true, import the script. This is documented here.

So, for instance:

Modernizr.load([
  {
    test: Modernizr.mq('only all and (min-width: 600px)'),
    yep: '/js/skrollr.js',
  }
]);
网友答案:

Use the skrollr.destroy() function in combination with enquire.js (mediaqueries for js).

enquire.register("screen and (min-width: 960px)", {

    match : function() {
        var s = skrollr.init();
    },      

    unmatch : function() {
        var s = skrollr.destroy();
    },    

    deferSetup : true,

});
分享给朋友:
您可能感兴趣的文章:
随机阅读: