【问题标题】:Turn Stellar.js on and off runtime打开和关闭运行时 Stellar.js
【发布时间】:2014-08-05 01:03:01
【问题描述】:

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

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

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

    });

【问题讨论】:

    标签: javascript stellar.js


    【解决方案1】:

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

    查看 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,
            });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 2023-03-27
      相关资源
      最近更新 更多