


Animate custom animation that simulates jquery implemented using js (2.5K)_jquery
Later I found out it was pretty good. Might as well keep writing.
This version is basically the same as jquery’s animate.
I mean the effect is basically the same. (The efficiency has not been tested yet.);
If there are professional testers, please help me test it.
1: Function description
Compatible with mainstream browsers.
1: Support callback function;
2: Support cascade animation call;
3: Support delay animation queue delay;
4: Support stop animation;
5: Support opacity transparency change ;
6: Support = -= *= /= operation;
7: Support unit operation (px, %);
2: Instructions for use
jelle(A).animate(B, C , D);
A: The ID of the dom element that needs to be animated;
B: The main parameters of the animation are passed {key, val, key2, val2}; such as {width:'100px',height:' =100px ',opacity:0.5},
opacity--transparency change supports = -= *= /= operations.
C: animation execution time, in milliseconds; [optional default 500 milliseconds];
D: callback function; [optional]
3: method description
1: animate() method
jelle('cc').animate({width:'100px'},300,function(){alert('Complete')});//The width of cc changes to 100px in 300 milliseconds animation The end pops up 'Complete'
2:stop() method
jelle('cc').stop();//Stop the animation being played on the cc object.
3: delay() method
jelle('cc').delay(1000).animate({width:'100px'}); //Changes in the width of cc will be executed with a delay of 1 second.
I will keep improving him.
var jelle = function(id){
var $ = function(id){ return document.getElementById(id); },
elem = $(id),//Object
f = 0, _this = {}, lazy = 10, lazyque = 10,//f animation counter lazy animation delay lazyque queue delay
//You can change the operator to make your animation different
tween = function(t, b, c, d){ return - c * (t /= d) * (t - 2) b},
// adv is used for = -= *= /= operation
adv = function(val, b){
var va, re= /^([ -\*/]=)([-]?[d.] )/ ;
if (re.test( val)){
var reg = val.match(re);
reg[2] = parseFloat(reg[2]);
switch ( reg[1] ){
case ' = ':
va = reg[2];
break;
case '-=':
va = -reg[2];
break;
case '*=' :
va = b*reg[2] - b;
break;
case '/=':
va = b/reg[2] - b;
break;
}
return va;
}
return parseFloat(val) - b;
}
// elem.animate reads the animation queue used on the current dom element
elem .animate = elem.animate || [];
//stop function to be used
jelle[id]= {};
jelle[id]['stop'] = true;
//alert(jelle[id]['stop'])
// The unified queue entry is used to conveniently set the delay, and stop
_this.entrance = function(fn, ags, lazytime){
/ /fn Call function ags parameter lazytime delay time
setTimeout(function(){
fn(ags[0], ags[1], ags[2]);
}, (lazytime || 0) );
}
// This method of stopping animation is not available yet
_this.stop = function(){
jelle[id]['stop'] = false;
elem.animate .length=0;
$(id).animate.length=0;
return _this;
}
// Queue operation
_this.queue = function(){
if (elem.animate && f == elem.animate[0].length){
f = 0; // Clear counter
elem.animate[0].callback ? elem.animate[0].callback .apply(elem) : false;
// Determine whether there is animation waiting to be executed
if (elem.animate.length > 1){
elem.animate[0].callback = elem.animate [1].callback;
elem.animate = $(id).animate || [];// Get the latest animation queue from the dom object
elem.animate.shift();// Clear the just executed Completed animation queue
$(id).animate = elem.animate;// Update the new queue to dom
var ea = elem.animate[0];
// Play the queue animation in a loop
for(var i = 0; i ea[i][0] === 'opacity' ? _this.entrance(_this.alpha, [ea[i][ 1], ea[i][2]], lazyque):
_this.entrance(_this.execution, [ea[i][0], ea[i][1], ea[i][2] ], lazyque);
}
}else{
elem.animate.length = 0; // The queue is clear
$(id).animate.length = 0; // The queue is clear
}
}
}
//Set lazy method, future queue animation delay time
_this.delay = function(val){
lazyque = val;
return _this;
}
//Animation changes
_this.execution = function(key, val, t){
//alert(val)
var s = (new Date()).getTime (), d=t || 500 ,
b = parseFloat(elem.style[key]) || 0 ,
c = adv(val, b) ,// adv is used to set advanced operations such as = -= etc.
un = val.match(/d (. )/)[1];// unit
(function(){
var t = (new Date()).getTime( ) - s;
if (t > d){
t = d;
elem.style[key] = parseInt(tween(t, b, c, d)) un;
_this.queue(); // Operation queue
return _this;
}
elem.style[key] = parseInt(tween(t, b, c, d)) un;
jelle[ id]['stop'] && setTimeout(arguments.callee, lazy);
// _this.entrance(arguments.callee,[1,1,1],lazy);
// arguments.callee anonymous Function recursive call
})();
}
// Entry
_this.animate = function(sty, t, fn){
// sty, t, fn are changes respectively Parameter key, val form, animation time, callback function
var len = elem.animate.length; // len checks the animation queue length
elem.animate[len] = [];
elem.animate [len].callback = fn;
//Multi-key loop setting changes
for(var i in sty){
elem.animate[len].push([i, sty[i], t ]);
if(len == 0){
i == 'opacity' ? _this.entrance(_this.alpha, [sty[i], t], lazyque) :
_this.entrance (_this.execution, [i, sty[i], t], lazyque);
}
}
$(id).animate = elem.animate;//Add a new animation queue to
return _this on the dom element;
}
// Code for transparency change
_this.alpha = function(val, t){
var s = (new Date()).getTime (),
d = t || 500, b, c;
if( document.defaultView ){
b = document.defaultView.getComputedStyle(elem,null)['opacity'] || 1 ,
c = adv(val,b) * 100;
(function(){
var t = (new Date()).getTime() - s;
if(t > d){
t = d;
elem.style['opacity'] = tween(t, (100 * b), c, d) / 100;
_this.queue(); // Queue control
return _this;
}
elem.style['opacity'] = tween(t, (100 * b), c, d) / 100;
jelle[id][' stop'] && setTimeout(arguments.callee, lazy);
})()
}else{
b = elem.currentStyle['filter'] ?
(elem.currentStyle['filter '].match(/^alpha(opacity=([d.] ))$/))[1]/100 : 1;
c = adv(val, b) * 100;
(function( ){
var t = (new Date()).getTime() - s;
if (t > d){
t = d;
elem.style['filter'] ='alpha(opacity=' tween(t, (100 * b), c, d) ')';
_this.queue(); // Queue control
return _this;
}
elem.style['filter'] = 'alpha(opacity=' tween(t, (100*b) , c, d) ')';
jelle[id]['stop'] && setTimeout (arguments.callee, lazy);
})()
}
}
return _this;
}
Code packaging Download
programs may be modified every day. If you want the latest ainimate, you can contact me by email.
The above code is no longer up to date.
Several errors have been corrected in the past two days.
This article comes from Blog Park jelle blog http://www.cnblogs.com/idche/

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
