<! Doctype html> <div id = "div1" style = "width: 100px; height: 50px; background: red; cursor: pointer; color: # fff; text-align: center; line-height: 50px; "data-mce-style =" width: 100px; height: 50px; background: red; cursor: pointer; color: # fff; text-align: center; line-height: 50px; "> click </div> <script type =" text/javascript "> (Function ($ ){ Window. $ =$; }) (Function (){ Var rquickExpr =/^ (? : # ([\ W-] *) $ /; Function aQuery (selector ){ Return new aQuery. fn. init (selector ); } /** * Animation * @ Return {[type]} [description] */ Var animation = function (){ Var self = {}; Var Queue = []; // animation Queue Var fireing = false // animation lock Var first = true; // triggered through the add Interface Var getStyle = function (obj, attr ){ Return obj. currentStyle? Obj. currentStyle [attr]: getComputedStyle (obj, false) [attr]; } Var makeAnim = function (element, options, func ){ Var width = options. width // Encapsulate the specific execution Algorithm // Css3 // SetTimeout Element. style. webkitTransitionDuration = '2000ms '; Element. style. webkitTransform = 'translate3d ('+ width + 'px, 0, 0 )'; // Listen to the animation Element. addEventListener ('webkittransitionend', function (){ Func () }); } Var _ fire = function (){ // Adding an animation is being triggered If (! Fireing ){ Var onceRun = Queue. shift (); If (onceRun ){ Fireing = true; // Next OnceRun (function (){ Fireing = false; _ Fire (); }); } Else { Fireing = true; } } } Return self = { // Add a queue Add: function (element, options ){ Queue. push (function (func ){ MakeAnim (element, options, func ); }); // If a queue triggers an animation immediately If (first & Queue. length ){ First = false; Self. fire (); } }, // Trigger Fire: function (){ _ Fire (); } } }(); AQuery. fn = aQuery. prototype = { Run: function (options ){ Animation. add (this. element, options ); Return this; } } Var init = aQuery. fn. init = function (selector ){ Var match = rquickExpr.exe c (selector ); Var element = document. getElementById (match [1]) This. element = element; Return this; } Init. prototype = aQuery. fn; Return aQuery; }()); // Dom Var oDiv = document. getElementById ('div1 '); // Call ODiv. onclick = function (){ $ ('# Div1'). run ({ 'Width': '123' }). Run ({ 'Width': '123' }). Run ({ 'Width': '123' }); }; </Script> |