jQuery源码分析17: .toggle()
来源:互联网 发布:数字创意产业人工智能 编辑:程序博客网 时间:2024/06/06 05:38
jQuery源码分析17: .toggle()
jQuery.extend({
// A global GUID counter for objects
guid: 1,
});
jQuery.fn.extend({
toggle: function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
guid = fn.guid || jQuery.guid++,
i = 0,
toggler = function( event ) {
// Figure out which function to execute
var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
// Make sure that clicks stop
event.preventDefault();
// and execute the function
return args[ lastToggle ].apply( this, arguments ) || false;
};
// link all the functions, so any of them can unbind this click handler
toggler.guid = guid;
while ( i < args.length ) {
args[ i++ ].guid = guid;
}
return this.click( toggler );
},
});
// Save the old toggle function
_toggle: jQuery.fn.toggle,
toggle: function( fn, fn2, callback ) {
var bool = typeof fn === "boolean";
if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
this._toggle.apply( this, arguments );
} else if ( fn == null || bool ) { //< 当调用$(elem).toggle([true|false|\s*]);时相当于.show(),.hide()
this.each(function() {
var state = bool ? fn : jQuery(this).is(":hidden");
jQuery(this)[ state ? "show" : "hide" ](); //< <==> jQuery(this)['show'](),jQuery(this)['hide']()
});
} else {
this.animate(genFx("toggle", 3), fn, fn2, callback);
}
return this;
},
jQuery.extend({
// A global GUID counter for objects
guid: 1,
});
jQuery.fn.extend({
toggle: function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
guid = fn.guid || jQuery.guid++,
i = 0,
toggler = function( event ) {
// Figure out which function to execute
var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
// Make sure that clicks stop
event.preventDefault();
// and execute the function
return args[ lastToggle ].apply( this, arguments ) || false;
};
// link all the functions, so any of them can unbind this click handler
toggler.guid = guid;
while ( i < args.length ) {
args[ i++ ].guid = guid;
}
return this.click( toggler );
},
});
// Save the old toggle function
_toggle: jQuery.fn.toggle,
toggle: function( fn, fn2, callback ) {
var bool = typeof fn === "boolean";
if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
this._toggle.apply( this, arguments );
} else if ( fn == null || bool ) { //< 当调用$(elem).toggle([true|false|\s*]);时相当于.show(),.hide()
this.each(function() {
var state = bool ? fn : jQuery(this).is(":hidden");
jQuery(this)[ state ? "show" : "hide" ](); //< <==> jQuery(this)['show'](),jQuery(this)['hide']()
});
} else {
this.animate(genFx("toggle", 3), fn, fn2, callback);
}
return this;
},
- jQuery源码分析17: .toggle()
- JQuery toggle使用分析
- jquery.toggle
- jQuery-toggle()
- jQuery toggle()
- jQuery toggle
- jquery点击toggle并改变图片src源码
- [ jQuery ] jQuery 源码分析!
- jQuery方法Toggle()应用
- jQuery中的toggle方法
- jquery toggle用法
- jquery toggle使用
- jquery toggle问题
- jquery 里面toggle使用
- Jquery ---鼠标事件toggle
- jQuery 效果 - toggle() 方法
- jQuery 效果 - toggle() 方法
- 【JQuery】toggle函数
- eclipse安装jQueryWTP
- C# 封装控件 学习(4)
- COLUMNPROPERTY (Transact-SQL)
- ubuntu 中crontab使用
- 如何让你的android平台也支持fuse
- jQuery源码分析17: .toggle()
- 暗时间--平凡与优秀间的距离
- Eclipse 代码提示功能设置
- 根據方法名(含參或無參)執行方法
- AS地址整理
- 自定义tableViewCell实现自定义表格(需代码实现)ui中tableviewcell设置成custom
- 加壳软件的实现原理篇
- Webissues1.0安装说明
- 解释器模式