In
jquery, besides asynchronous, what we need to use most is animation and special effects. If we want to give users a better experience,jqueryis the best choice, let us Let’s take a look at the detailed explanation ofjquery’s animation and special effects!
1. Show and hide hide() and show()
For animation, showing and hiding are the most basic One of the effects, this section briefly introduces the display and hiding of jQuery.
点击按钮,看看效果
本节主要降级和学习jQuery的自动显隐,渐入渐出、飞入飞出。自定义动画等。 1.显示和隐藏hide()和show() 对于动画来说,显示和隐藏是最基本的效果之一,本节简单介绍jQuery的显示和隐藏。
The above is a test of the hide() and show() functions.
2. Use the show(), hide() and toggle() methods
The previous example uses show() and toggle() The hide() method has been briefly introduced. In fact, these two methods can accept parameters to control the display and hide process.
The syntax is as follows
show(duration,[callback]); hide(duration,[callback]);
Among them, duration represents the length of animation execution time, which can be a string representing speed, including slow, normal, fast. It can also be an integer representing time (milliseconds). callback is an optionalcallback function. Executed after the animation completes.
The example is the same as the first example, except that time parameters are added to hide() and show(). In fact, toogle() can also add event parameters.
3. Use fadeIn() and fadeOut() methods
For animation effects to show and disappear, jQuery also provides fadeIn( ) fadeOut are two practical methods. Their animation effects are similar to fading, and their syntax is exactly the same as slow() and hide().
fadeIn(duration, [callback]); fadeOut(duration, [callback]);
Example
Usage of fadeTo() method.
fadeTo() method gradually changes the opacity of the selected elements to the specified value.
Example:
fadeOut related parameters
speed
Optional. Specifies the speed at which an element changes from the current transparency to the specified transparency.
Possible values:
Milliseconds (e.g. 1500)
"slow"
"normal"
"fast"
opacity Required. Specifies the transparency to fade in or out. Must be a number between 0.00 and 1.00.
callback
Optional. The function to be executed after the fadeTo function is executed.
To learn more about callbacks, visit our jQuery Callback chapter.
This parameter cannot be set unless the speed parameter is set.
4. Slide slideUp and slideDown effects
Several mentioned above For animation effects, jQuery also provides slideUp() and slideDown() to simulate a slide-like curtain effect in PPT, which is exactly the same as slow() and hide().
The above code defines a div and an img, which are combined together using the add method.
5. Custom animation
Considering the versatility of the framework and the size of the code file, jQuery cannot cover all animation effects, but It provides the animate() method, which enables developers to customize animations. This section mainly introduces the two forms and applications of the animate() method.
The animate() method gives developers a lot of space. It comes in two forms. The first form is more commonly used. The usage is as follows
animate(params,[duration],[easing],[callback])
where params is the list of css properties that you want to change, and the final value you want to change to, and duration is optional , which has exactly the same meaning as the parameters of show()/hide(). Easing is an optional parameter, usually used by animation plug-ins. Used to control the rhythm change process. jQuery only provides two values: linear and swing. callback is an optional callback function. Fires after the animation completes.
requires attention. Variables in params follow the camel naming method. For example, paddingLeft cannot be written aspadding-left. In addition, params can only be attributes represented by numerical values in CSS. For example, properties such as width.top.opacity and
likebackgroundColor are not supported by animate.
动画!
In params, jQuery can also use "+=" or "-=" to indicate relative changes. For example,
动画!
first performabsolute positioning of the div, and then use -= and += in animate() to achieve relative left movement and relative right movement respectively.
The animate() method has another form, as shown below:
animate(params,options)
Among them, params is exactly the same as the first form, and options is animation. Optional parameter list, mainly including duration, esaing, callback, queue, etc., among which duration.easing.callback is exactly the same as the first form, queue is a Boolean value, indicating that when there are multiple animate() forming jQuery, the current animate( ) Immediately following the next animate(), should it be executed in sequence (true) or false at the same time?
The following example shows the second usage of animate().
Block1Block2
以上两个div块同时运用了三个动画效果,其中第一个div快的第一个动画添加了queue:false参数,使得前两项两个动画同时执行。可以通过重置反复测试,熟悉animate()第二种形式。
以上就是本文的全部内容了,希望大家能够喜欢。
相关推荐:
The above is the detailed content of Detailed explanation of jQuery animation and special effects. For more information, please follow other related articles on the PHP Chinese website!