Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在运行时打开和关闭Stellar.js_Javascript_Stellar.js - Fatal编程技术网

Javascript 在运行时打开和关闭Stellar.js

Javascript 在运行时打开和关闭Stellar.js,javascript,stellar.js,Javascript,Stellar.js,有没有办法在代码中打开和关闭stellar.js?我尝试用不同的参数调用“stellar”方法,但似乎它只起作用一次: $(document).ready(function() { $.stellar({ verticalScrolling: true, verticalOffset: 0, }); $.stellar({ vertic

有没有办法在代码中打开和关闭stellar.js?我尝试用不同的参数调用“stellar”方法,但似乎它只起作用一次:

    $(document).ready(function() {
        $.stellar({
                verticalScrolling: true,
                verticalOffset: 0,
            });

        $.stellar({
                verticalScrolling: false, // is not turning scrolling off
                verticalOffset: 0,
            });

    });

如果要重新加载插件,请在调用初始化函数之前重置插件

检查stellar.js中的函数代码。如果选项==='destroy',则会重置插件stellar

$.fn[pluginName] = function (options) {
    var args = arguments;
    if (options === undefined || typeof options === 'object') {
        return this.each(function () {
            if (!$.data(this, 'plugin_' + pluginName)) {
                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
            }
        });
    } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
        return this.each(function () {
            var instance = $.data(this, 'plugin_' + pluginName);
            if (instance instanceof Plugin && typeof instance[options] === 'function') {
                instance[options].apply(instance, Array.prototype.slice.call(args, 1));
            }
            if (options === 'destroy') {
                $.data(this, 'plugin_' + pluginName, null);
            }
        });
    }
};
因此,您的代码可以如下所示:

$(document).ready(function() {
    $.stellar({
            verticalScrolling: true,
            verticalOffset: 0,
        });

    $.stellar("destroy");

    $.stellar({
            verticalScrolling: false, // is not turning scrolling off
            verticalOffset: 0,
        });

});