每次加载页面时,我的canvi菜单都会自动打开。我该如何阻止呢? 这是我的代码:这是一个插件jquery。我使用drupal 8:
我的代码正常工作。有必要关闭default的值...我想在“ default”中更改我的值,以便它不会对加载自动打开。
;(function ( $, window, document, undefined ) {
// Create the defaults once
var pluginName = "certinaOffcanvas",
defaults = {
top: 0,
bottom:0,
togglerSelector: '.offcanvas-toggle',
togglerOpenClass: 'is-open'
};
// The actual plugin constructor
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this._isClosed = true;
this.init();
}
Plugin.prototype = {
init: function() {
var plugin = this;
$(this.element).css({
top: this.options.top,
bottom: this.options.bottom,
// Initialize the offcanvas on closed position
transform: 'translateX(-100%)'
});
// Attach event handler on the toggler
$(this.options.togglerSelector).on('click', function(){
plugin.toggle();
});
// Attah event handler on the document
// Capture clicks outside the offcanvas and trigger a close method
$(document).on('click', function(e){
if(plugin._isClosed) { return };
if(
$(e.target).parents('.offcanvas').length == 0 &&
$(e.target).parents(plugin.options.togglerSelector).length == 0 &&
!$(e.target).hasClass( plugin.options.togglerSelector.replace('.', '') )
) {
plugin.close();
}
})
},
close: function(){
$(this.element).css({
transform: 'translateX(-100%)'
});
this._isClosed = true;
$(this.options.togglerSelector).removeClass(this.options.togglerOpenClass);
$(this.element).trigger('offcanvasClose');
},
open: function(){
$(this.element).css({
transform: 'translateX(0%)'
});
this._isClosed = false;
$(this.options.togglerSelector).addClass(this.options.togglerOpenClass);
$(this.element).trigger('offcanvasOpen');
},
toggle: function(){
if(this._isClosed) {
this.open();
} else {
this.close();
}
},
};
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, pluginName)) {
$.data(this, pluginName, new Plugin( this, options ));
}
});
};
})( jQuery, window, document );