到达断点时禁用scrollify插件(Disable scrollify plugin when reaches breakpoint)

这是我想在浏览器达到768px宽度的Bootstrap断点时禁用的脚本:

$(function() { $.scrollify({ /*section: "section",*/ interstitialSection: "interstitialSection", offset: 30, }); });

提前致谢。

This is the script I want to disable when the browser reaches the Bootstrap breakpoint of 768px width:

$(function() { $.scrollify({ /*section: "section",*/ interstitialSection: "interstitialSection", offset: 30, }); });

Thanks in advance.

最满意答案

您可以在到达断点时禁用并启用scrollify插件,如下所示:

$(window).resize(function() { var width = $(this).width(); if(width < 768) { $.scrollify.disable(); } else { $.scrollify.enable(); } }); $(window).trigger('resize');

您可以包含去抖功能,因此禁用和启用将在调整大小后仅启动50ms(请查看Codepen示例)。

CODEPEN

You can disable and enable scrollify plugin when you reach your breakpoint like this:

$(window).resize(function() { var width = $(this).width(); if(width < 768) { $.scrollify.disable(); } else { $.scrollify.enable(); } }); $(window).trigger('resize');

You can include debounce function, so disable and enable will fire only 50ms after resizing is done (check Codepen example).

CODEPEN

更多推荐