


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.length; 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/

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
