javascript - 打开和关闭 Stellar.js 运行时

标签 javascript stellar.js

有没有办法在代码中打开和关闭 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,
        });

});

关于javascript - 打开和关闭 Stellar.js 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25129791/

相关文章:

javascript - 使用 Google 脚本对 API 调用进行身份验证

javascript - 位置为 : auto to right: 0 won't animate 的 span 的 CSS 动画

javascript - Jquery/JS 引用单个单元格内容

javascript - 如何从 json 响应中删除字符串

css - 在 3G 连接上加载图像时出现问题

css - 如何制作包含 stellar.js 的响应式网站?

javascript - 使用 Stellar.js 时,绝对定位元素在 FireFox 中定位不正确

javascript - 更改 Javascript 生成的表中各个列的 CSS 样式

ios - css 背景大小 : contain ignored on IOS?

jquery - 滚动 stellar.js 视差元素时初始顶部位置发生变化