我正在将原型插件移植到jQuery。
插件使用禁止的方法来收集对象文字中的所有插件方法,然后像[object]一样调用它们。[方法]
我不明白的是,在所有这些方法中,都使用了似乎是全局的且未作为参数或属性传递的属性(在脚本的开头定义,即var x = 0,var y = 0等)。具体方法。
我将如何在jQuery中做到这一点,并且可能吗?
请参考以下代码中的“ var1”。它将在哪里设置,以便所有方法都可以访问它?
例:
;(function($){
var methods = {
init : function(options) {
var config = {
// default options...
}
// overide config
var settings = $.extend(config, options);
return this.each(function() {
// init code goes here...
});
},
function1 : function() {
function2();
},
function2 : function() {
$(selector).css({
width : var1,
});
},
}
$.fn.[PLUGINNAME] = function(method) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 …Run Code Online (Sandbox Code Playgroud) 请有人解释为什么以下不起作用.这发生在相同的单击事件上,但CSS函数不是直接的,所以我不想在动画函数上使用回调,如果可能的话.
注意:动画会触发,但css不会.
container.animate({
left : (posLeft + slideWidth),
});
container.css({
left : '-'+(itemsLength + startX)+'px',
});
Run Code Online (Sandbox Code Playgroud)