This article will give you an in-depth introduction to the usage of Animate in jQuery. It follows the previous article [JQuery - In-depth Learning of Animate (2)] so that everyone can further understand the use of animate in jQuery. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
progress
Type: Function( Promise animation, Number progress, Number remainingMs )
A function called after each step of animation is completed, regardless of animation As many properties as there are, each animated element performs a separate function. (version added: 1.8)
Number progress: Indicates the current animation progress level 0~1
Number remainingMs: It is the difference between the final animation property value and the difference
CSS code :
.block { position: relative; background-color: #abc; width: 40px; height: 40px; float: left; margin: 5px; } .wrap{position:relative;float:left;width:400px;} #go{border:1px solid red;color:blue;cursor:pointer;}
Html code:
<p> <button id="go">Run>></button> </p> <p class="wrap"> <p class="block"></p> <p class="block"></p> <p class="block"></p> <p class="block"></p> <p class="block"></p> <p class="block"></p> </p>
Javscript code:
var j=0,k=0; $( "#go" ).one("click",function() { $( ".block:first" ).animate( { left: 100,top:200 }, { duration: 1000, step: function( now, fx ){ k++; if(k==1) console.log(fx); $( ".block:gt(0)" ).css( fx.prop, now );//注意到prop的变化性 }, progress:function(a,p,r){ j++; if(j==1){console.log(a);console.log(a.props)} a.progress(function(){ console.log("Hi"+j);//注意progress的运行时机 }); console.log(p+"---"+r);//注意p,r的变化 } }); });
Observe the value after the output on the console, you will get something!
Make a simple progress bar animation. It starts from red, turns to green at 30%, and turns to pink at 60%. There is no color change plug-in, and the choice is to replace the class. Let everyone have an understanding of this progress and step application. I hope this example will inspire others!
CSS code:
.progressBar { float: left; position: relative; width: 500px; height: 30px; border: 1px solid orange; background-color: #999; } .progressBar p { padding: 0; margin: 0; position: absolute; left: 0; top: 0; height: 30px; } .red { background-color: red; } .green { background-color: green; } .pink { background-color: pink; }
Html code:
<p class="progressBar"> <p class="progress"></p> </p>
Javascript code:
$(".progressBar p").addClass("red").animate({ "width": 500 }, { duration: 5000, progress: function(a, p, r) { if(p > 0.3 && !$(this).hasClass("green")) $(this).removeClass().addClass("green"); if(p > 0.6 && !$(this).hasClass("pink")) $(this).removeClass().addClass("pink"); } });
Summary: The above is the entire content of this article, I hope it can help Everyone’s learning helps.
The above is the detailed content of In-depth learning of jQuery Animate (3). For more information, please follow other related articles on the PHP Chinese website!