Animation effects, if used comprehensively, can also be used to simply implement the effects of various jquery plug-ins using simple codes
This article refers to the book "A Brief Talk on jquery", organizes it, and combines it with my own reality It is based on experience and can be regarded as a learning manual
The code was all messed up when editing. I reorganized it. The code format may still be a bit messy. Please forgive me
Show, hide and combination (toggle) Effect
1.show(speed,callback);
Explanation: This method can display hidden elements, and the parameters are also default, that is, written in the form of show()
speed --- There are 3 parameters to specify the display speed. You can choose slow, normal, fast, or you can specify the number yourself (unit: milliseconds)
callback---callback function
The following is a simple example
Explanation: It can be said to be a synthesis of the above two methods, which can replace toggle(); if you have carefully read the introduction of the above methods, you should know how to use them. In fact, these methods The usage and parameters are the same, but the display form is different. I won’t write the example
Fade in and out effect of three elements
1.fadeIn(speed,[callback]);
Description: Implement fade-out effect, used to display hidden elements
2.fadeOut(speed,[callback]);
Description: Implement fade-in effect, used to hide displayed elements
3, fadeTo(speed,opactity,callback);
Description: This method is used to change the transparency of the displayed element
Parameters: speed, callback have the same parameters as other animation methods introduced above. The opactity parameter represents transparency, and the value range is 0-1
var callback=function(){
//alert("I am Callback function");
};
var f1=function(){ $("#t1").fadeTo(1000,0.3,callback);//0.3 is 30% transparency
};
$("#b1").click(f1);
4. Custom animation
Note: As you can see from the previous one, two, and three, the display of elements includes show, slideDown, fadeIn, and the hidden animation effects of hide, slideUp, and fadeOut
, combine effects toggle, slideToggle, change transparency effect fadeTo, we can also customize some animation effects if needed
How to use custom animation: animate(params,speed,callback);
Parameter description: params---a set of style attributes and their values as animation attributes and final values
speed----Same as the speed attribute in the method introduced earlier
callback---callback function
Note: The style attributes of params must be written in camel case, that is, margin-left should be slightly smaller than marginLeft.
The following is an example
var callback =function(){
//alert("I am a callback function");
} ;
var par={ height: "70%" };
var f1=function(){
$("#t1").animate(par,1000,callback);
};
$("#b1").click(f1);
Html code