[英]Turn Stellar.js on and off runtime
Is there a way to turn stellar.js on and off in code? 有没有办法在代码中打开和关闭stellar.js? I've tried to call "stellar" method with different parameters but seems like it only works once:
我试图用不同的参数调用“ stellar”方法,但似乎只能使用一次:
$(document).ready(function() {
$.stellar({
verticalScrolling: true,
verticalOffset: 0,
});
$.stellar({
verticalScrolling: false, // is not turning scrolling off
verticalOffset: 0,
});
});
If you want to reload the plugin, reset it before calling initialization function. 如果要重新加载插件,请在调用初始化函数之前将其重置。
Check the function code in stellar.js. 检查stellar.js中的功能代码。 If the options === 'destroy', plugin stellar is reset.
如果选项==='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);
}
});
}
};
So your code could be as following: 因此,您的代码可能如下所示:
$(document).ready(function() {
$.stellar({
verticalScrolling: true,
verticalOffset: 0,
});
$.stellar("destroy");
$.stellar({
verticalScrolling: false, // is not turning scrolling off
verticalOffset: 0,
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.