JQuery1.5.1 view the animate method source code

Source: Internet
Author: User

Copy codeThe Code is as follows:/* 7536-7646 */
Animate: function (prop, speed, easing, callback ){
If (jQuery. isEmptyObject (prop )){
Return this. each (optall. complete );
}
// #7864 rows this. options. complete. call (this. elem) Enables continuous animation execution, such as $ ('selector '). animate ({prop1}, speed1 ). animation queue such as animate ({prop2}, speed2;
Return this [optall. queue === false? "Each": "queue"] (function (){
// XXX 'this' does not always have a nodeName when running
// Test suite
Var opt = jQuery. extend ({}, optall), p,
IsElement = this. nodeType = 1,
Hidden = isElement & jQuery (this). is (": hidden "),
Self = this;
// The prop of the animation to be executed. The prop is generally a plainObj, in the form of {key1: value1, key2: value2 };
For (p in prop ){
// Modify the cameCase. For example, if magrin-top needs to be changed to the marginTop attribute, the attribute is changed to the marginTop attribute. For details, refer to the cameCase method;
Var name = jQuery. camelCase (p );
// Fix attribute; mainly the attributes of camelcase;
If (p! = Name ){
Prop [name] = prop [p];
Delete prop [p];
P = name;
}
// If you execute $ (..). show | $ (..). hide; if this element is hidden and hide is written in the animation, run callbacks directly;
If (prop [p] === "hide" & hidden | prop [p] === "show "&&! Hidden ){
Return opt. complete. call (this );
}
// If prop [key] = (height | width) and is a dom element, some special processing is required;
If (isElement & (p = "height" | p = "width ")){
// Make sure that nothing sneaks out
// Record all 3 overflow attributes 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;
}
}
}
}
// If prop [key] is an array, use only the first value 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 ){
// If the animation element overflow has been set, set it to hidden temporarily;
This. style. overflow = "hidden ";
}
// The current animation key-value pair is actually prop;
Opt. curAnim = jQuery. extend ({}, prop );
// This is the core of the animation and processes each prop [key;
JQuery. each (prop, function (name, val ){
// Obtain an Fx object. Each input parameter is set as the property of this object. self indicates the animation element itself; opt indicates the previously generated object;
Var e = new jQuery. fx (self, opt, name );
// When the show | hide operation is executed, prop = fxAttrs (see show | hide method)
If (rfxtypes. test (val )){
E [val = "toggle "? Hidden? "Show": "hide": val] (prop );
} Else {
Var parts = rfxnum.exe c (val ),
// Start stores the initial value, which may be in the style or css. If the value = null, undefiend, auto, and 0 are set to 0;
Start = e. cur ();
If (parts ){
// End refers to the size of the change volume, for example: {left:-= 66px}, then end = 66;
Var end = parseFloat (parts [2]),
// Unit operator, that is, px, %; if it is a number that cannot contain units, such as z-index, it is set to NULL; otherwise, it is set to px;
Unit = parts [3] | (jQuery.css Number [name]? "": "Px ");
// We need to compute starting value
// If it is not px, such as %, em, and so on;
If (unit! = "Px "){
// Set the attribute name to (end | 1) + unit. If end = 0, set it to 1. The start value to start = (end | 1) /e. cur () * start;
JQuery. style (self, name, (end | 1) + unit );
// Here e. cur () and start = e. cur (); is different, because jQuery. the execution of style (self, name, (end | 1) + unit) changes the start, which is used to process the case where end is 0, because e. the cur () value cannot be 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]) {
// The end value is set as the variable value after calculation;
End = (parts [1] = "-= "? -1: 1) * end) + start;
}
E. custom (start, end, unit );
// If there is no digital operation, ''is not input '';
} Else {
E. custom (start, val ,"");
}
}
});

// For JS strict compliance
Return true;
});
},

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.