jQuery1.5.1 animate方法源码阅读 - Web前端
作者:98wpeu发布时间:2026-07-01分类:网页前端技术浏览:2
导读:复制代码代码如下:/*7536-7646*/Animate:function(prop,speed,Easing,callback){if(JQuery.i...
复制代码 代码如下:
/*7536-7646*/
Animate: function( prop, speed, Easing, callback ) {
if ( JQuery.iSEMptyObject( PRop ) ) {
returnthis.each( optall.complete );
}
//#7864行this.options.complete.call( this.elem )使得其可以不断的连续执行动画,比如$(‘selector').animate({prop1},speed1).animate({prop2},speed2)这样的动画队列;
return this[ optall.queue === false ? "each" : "queue" ](function() {
// XXX 'this' does not always have a nodeName when running the
// test sUIte
var opt = jQuery.extend({}, optall), p,
isElement = this.nodeType === 1,
hidden = isElement && jquery(this).is(":hidden"),
self = this;
//要执行动画的prop,prop一般是一个plAInObj,形如{key1:value1,key2:value2};
for ( p in prop ) {
//驼峰改写,有些比如magrin-top需要变成驼峰的属性即变成marginTop;见cameCase方法;
var name = jquery.camelCase( p );
//fix属性;主要是前面camelcase的属性;
if ( p !== name ) {
prop[ name ] = prop[ p ];
delete prop[ p ];
p = name;
}
//如果执行$(..).show||$(..).hide;如果这个元素本身是hidden,而动画里面又写hide,直接运行callbacks就可以了;
if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
return opt.complete.call(this);
}
//如果prop[key]==(height||width)并且是一个DOM元素;需要有些特殊的处理;
if ( isElement && ( p === "height" || p === "width" ) ) {
// Make sure that nothing sneaks out
// Record all 3 overflowattributes because ie does not
// change the overflow attribute when overflowX and
// overflowY are set to the same value
opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
// Set display property to inline-block for height/width
// Animations on inline elements that are having width/height
// animated
if ( JQuery.CSS( this, "display" ) === "inline" &&
jQuery.css( this, "float" ) === "none" ) {
if ( !jQuery.support.inlineblockNeedsLayout ) {
this.style.display = "inline-block";
} else {
var display = defaultDisplay(this.nodeName);
// inline-level elements accept inline-block;
// block-level elements need to be inline with layout
if ( display === "inline" ) {
this.style.display = "inline-block";
} else {
this.style.display = "inline";
this.style.Zoom = 1;
}
}
}
}
//如果prop[key]是一个数组;只用第一个值prop[p][0];
if ( jQuery.isArray( prop[p] ) ) {
// Create (if needed) and add to specialEasing
(opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
prop[p] = prop[p][0];
}
}
if ( opt.overflow != null ) {
//如果动画元素的overflow已经被设置的情况下,把它暂时为hidden;
this.style.overflow = "hidden";
}
//当前动画键值对,其实就是prop;
opt.curAnim = jQuery.extend({}, prop);
//这里便是动画的核心了,对每一个prop[key]进行处理;
jQuery.each( prop, function( name, val ) {
//获取一个Fx对象;传入的每一个参数都被设置成为这个对象的属性;其中self是指动画元素自身;opt是前面产生的对象;
var e = new jQuery.fx( self, opt, name );
//当执行show||hide操作的时候prop==fxAttrs(参见show||hide方法)
if ( rfxtypes.test(val) ) {
e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
} else {
var parts = rfxnum.exec(val),
//start保存了初始值,它可能在style,也可能在css中,如果该值==Null,undefIEnd,auto,0等将被设置为0;
start = e.cur();
if ( parts ) {
//end是指变化量的大小,比如:{left:-=66px},那么end=66;
var end = parseFloat( parts[2] ),
//单元运算符,就是px,%;如果是一些不能带单位的,比如z-index,设置为空,否则就设置为px;
unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
// We need to compute starting value
//如果不是px,比如%,em等等;
if ( unit !== "px" ) {
//设置该属性值name为(end || 1) + unit,如果end=0;设置为1;开始值被设置为start = ((end || 1) / e.cur()) * start;
jQuery.style( self, name, (end || 1) + unit);
//这里e.cur()和前面的start = e.cur();是不一样的,因为jQuery.style( self, name, (end || 1) + unit)的执行使得start被改变;用于处理end=0的情况;因为e.cur()作为除数,不能为0;
start = ((end || 1) / e.cur()) * start;
jQuery.style( self, name, start + unit);
}
// If a +=/-= token was provided, we're doing a relative animation
if ( parts[1] ) {
//end相应的被设置为运算后的变量值;
end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
}
e.custom( start, end, unit );
//如果没有数字化的运算;那么没传入的只能是'';
} else {
e.custom( start, val, "" );
}
}
});
// For JS strict compliance
return true;
});
},
/*7536-7646*/
Animate: function( prop, speed, Easing, callback ) {
if ( JQuery.iSEMptyObject( PRop ) ) {
returnthis.each( optall.complete );
}
//#7864行this.options.complete.call( this.elem )使得其可以不断的连续执行动画,比如$(‘selector').animate({prop1},speed1).animate({prop2},speed2)这样的动画队列;
return this[ optall.queue === false ? "each" : "queue" ](function() {
// XXX 'this' does not always have a nodeName when running the
// test sUIte
var opt = jQuery.extend({}, optall), p,
isElement = this.nodeType === 1,
hidden = isElement && jquery(this).is(":hidden"),
self = this;
//要执行动画的prop,prop一般是一个plAInObj,形如{key1:value1,key2:value2};
for ( p in prop ) {
//驼峰改写,有些比如magrin-top需要变成驼峰的属性即变成marginTop;见cameCase方法;
var name = jquery.camelCase( p );
//fix属性;主要是前面camelcase的属性;
if ( p !== name ) {
prop[ name ] = prop[ p ];
delete prop[ p ];
p = name;
}
//如果执行$(..).show||$(..).hide;如果这个元素本身是hidden,而动画里面又写hide,直接运行callbacks就可以了;
if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
return opt.complete.call(this);
}
//如果prop[key]==(height||width)并且是一个DOM元素;需要有些特殊的处理;
if ( isElement && ( p === "height" || p === "width" ) ) {
// Make sure that nothing sneaks out
// Record all 3 overflowattributes because ie does not
// change the overflow attribute when overflowX and
// overflowY are set to the same value
opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
// Set display property to inline-block for height/width
// Animations on inline elements that are having width/height
// animated
if ( JQuery.CSS( this, "display" ) === "inline" &&
jQuery.css( this, "float" ) === "none" ) {
if ( !jQuery.support.inlineblockNeedsLayout ) {
this.style.display = "inline-block";
} else {
var display = defaultDisplay(this.nodeName);
// inline-level elements accept inline-block;
// block-level elements need to be inline with layout
if ( display === "inline" ) {
this.style.display = "inline-block";
} else {
this.style.display = "inline";
this.style.Zoom = 1;
}
}
}
}
//如果prop[key]是一个数组;只用第一个值prop[p][0];
if ( jQuery.isArray( prop[p] ) ) {
// Create (if needed) and add to specialEasing
(opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
prop[p] = prop[p][0];
}
}
if ( opt.overflow != null ) {
//如果动画元素的overflow已经被设置的情况下,把它暂时为hidden;
this.style.overflow = "hidden";
}
//当前动画键值对,其实就是prop;
opt.curAnim = jQuery.extend({}, prop);
//这里便是动画的核心了,对每一个prop[key]进行处理;
jQuery.each( prop, function( name, val ) {
//获取一个Fx对象;传入的每一个参数都被设置成为这个对象的属性;其中self是指动画元素自身;opt是前面产生的对象;
var e = new jQuery.fx( self, opt, name );
//当执行show||hide操作的时候prop==fxAttrs(参见show||hide方法)
if ( rfxtypes.test(val) ) {
e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
} else {
var parts = rfxnum.exec(val),
//start保存了初始值,它可能在style,也可能在css中,如果该值==Null,undefIEnd,auto,0等将被设置为0;
start = e.cur();
if ( parts ) {
//end是指变化量的大小,比如:{left:-=66px},那么end=66;
var end = parseFloat( parts[2] ),
//单元运算符,就是px,%;如果是一些不能带单位的,比如z-index,设置为空,否则就设置为px;
unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
// We need to compute starting value
//如果不是px,比如%,em等等;
if ( unit !== "px" ) {
//设置该属性值name为(end || 1) + unit,如果end=0;设置为1;开始值被设置为start = ((end || 1) / e.cur()) * start;
jQuery.style( self, name, (end || 1) + unit);
//这里e.cur()和前面的start = e.cur();是不一样的,因为jQuery.style( self, name, (end || 1) + unit)的执行使得start被改变;用于处理end=0的情况;因为e.cur()作为除数,不能为0;
start = ((end || 1) / e.cur()) * start;
jQuery.style( self, name, start + unit);
}
// If a +=/-= token was provided, we're doing a relative animation
if ( parts[1] ) {
//end相应的被设置为运算后的变量值;
end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
}
e.custom( start, end, unit );
//如果没有数字化的运算;那么没传入的只能是'';
} else {
e.custom( start, val, "" );
}
}
});
// For JS strict compliance
return true;
});
},
- 上一篇:jQuery对表单元素的取值和赋值操作代码 - Web前端
- 下一篇:已经是最后一篇了
相关推荐
- jQuery实现的Email中的收件人效果(按del键删除) - Web前端
- jQuery对表单元素的取值和赋值操作代码 - Web前端
- 从零开始学习jQuery (六) jquery中的AJAX使用 - Web前端
- 精心收集的jQuery常用的插件1000 - Web前端
- jQuery实现公告文字左右滚动的实例代码 - Web前端
- 基于jquery的cookie的用法 - Web前端
- jquery选择器大全 全面详解jquery选择器 - Web前端
- 自制基于jQuery的智能提示插件一枚 - Web前端
- jQuery find和children方法使用 - Web前端
- jquery 学习之二 属性(类) - Web前端
- 网页前端技术排行
-
- 1【第六章】Foundation之按钮和下拉功能 - Web前端
- 2jQuery编写widget的一些技巧分享 - Web前端
- 3在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 4分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 9JS网页制作实例:标签云 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


