Before we understand what preprocessing is, let's look at a small example
<! DOCTYPE html>
<HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title> <style>#div1{width:300px;Height:300px;background:Red; } </style></Head><Body><DivID= "Div1"></Div><Scriptsrc= "Jquery-2.0.3.js"></Script><Script>$( function(){ $('#div1'). Animate ({width:'50%'}, -);} );</Script></Body></HTML>
You can see that when I change the width of the writing is 50%, and the initial width is 300px, then how to convert the two? This involves a preprocessing problem.
In line 7860, jquery defines a variable called tweeners,
In 7864 rows, the variable parts is used to receive a regular match to the value, that is, 50 and%
In 7865 rows, the variable unit is used to receive units, which is the PX
The next step is to convert the unit, which is a little bit more complicated to write.
The idea is to convert the 20px to a percentage first, for example, in this case, it is converted to 1.4% and then to 50%.
So what are some interesting ways to do it in sports? We continue to
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title> <style>#div1{width:300px;Height:300px;background:Red;position:Absolute; } </style></Head><Body><inputtype= "button"value= "Tap"><DivID= "Div1"></Div><Scriptsrc= "Jquery-2.0.3.js"></Script><Script>$( function(){ $('input'). Click (function() { $('#div1'). Animate ({width:'+=100'}, -); }); } );</Script></Body></HTML>
In this example, we use the + = notation, that is, each click will move 100px
The implementation of this part in the source code is also relatively simple
The principle is that after the end to determine whether there is still accumulation, if not accumulated directly to the parts[2] to pay the initial value is OK
Continue, when we write this, the run is OK
function () { $ (' input '). Click (function() { $ (' #div1 '). Animate ({' Margin-left ': 100}, }); } );
Or you can write like this.
function () { $ (' input '). Click (function() { $ (' #div1 '). Animate ({' MarginLeft ': 100}, 500 ); }); } );
The reason for this is that a compound style is handled in 8055 rows.
Not to be continued ...
jquery Source Code Analysis---motion animate preprocessing