to bind multiple event types, the sample code is as follows:
$ (function () {
$ ("div"). Bind ("mouseover mouseout", function () {
$ (this). Toggleclass ("over");
});
});
The code above has the same effect as the following code;
$ (function () {
$ ("div"). Bind ("MouseOver", function () {
$ (this). Toggleclass ("over")
});
$ ("div"). Bind ("Mouseout", function () {
$ (this). Toggleclass ("over")
});
});
animations in jquery:
1:show () Hide ()
hide () is equivalent to changing the display style of the element to the "none" code as follows:
$ ("element"). Hide (); = = $ ("element"). CSS ("display", "none");
2:fidein () fideout ( )
similar to the Hide () show () method, the Fidein method is (fade in) the content slowly displays, the Fideout method is (fades) the content slowly disappears,
$ ("div"). Toggle (function () {
$ (this). Next (). Fidein ();
},function () {
$ (this). Next (). Fideout (); The above method can add parameters such as show (1000); indicates that the content is displayed within 1000 milliseconds. At the same time can be used in the three parameters "slow" "normal" "fast" is 0.6 seconds, 0.4 seconds 0.2 seconds respectively.
});
3:slidup () Sliddown ( )
The Sliddown () element is extended from top to bottom, and slidup () is hidden down and up. The sample code is as follows:
$ ("#panel"). Toggle (function () {
$ (this). Slidup (+);
},function () {
$ (this). Sliddown (+);
})
In addition to the above three methods Jqury can also customize the animation method:
Animate (Params,speed,callback);
params: A mapping that contains style attributes and values, such as {property1: "value1", Property2: "value2" ....}
speed: Velocity parameter, optional.
callback: An optional function that executes after the animation is completed. The callback function applies to any Jqeury method.
The sample code is as follows:
$ (function () {
$ ("#panel"). Click (function () {
$ (this). Animate ({left: "500px"},3000);
});
});
You can also set the accumulation or decrement. Just add + = or-= before 500px;
You can also set multiple animations, just add more elements in {}, such as {left: "+=500px", Heigh: "-=300px"};
all of the above animations are performed simultaneously, and can be animated in a certain order: for example:
$ (this). Animate ({left: "500px"},3000)
. Animate ({heigh: "300px"},3000);
Comprehensive Animation code examples:
$ ("#penal"). CSS ("opacity", 0.5);
$ ("#penal"). Animate ({left: "500px", Top: "200px"},3000)
. Animate ({height: "300px", Width: "200px"},3000)
. Fadout ("slow");
Animation callback function:
determine if the animation is accumulating:
To avoid animations that result from an animation that is inconsistent with the user's behavior, we need to determine if the element is animated, as shown in the following example code:
if (!$ (Element). Is (": Animate")) {
//If you are not currently animating, add a new animation.
};
Delay Animation:
$ (this). Animate ({left: "300px", Height: "200px", Opacity: "1"},3000)
. Delay (+)
. Animate ({width: "300px", Top: "300px", Opacity: "I"},2000)
. Delay (in)
. Animate ({width: "300px", Top: "300px", Opacity: "I"},2000);
Other animation methods:
Toggle (Speed,[callback]). This method toggles the visible state of the original element,
Slidetoggle (Speed,[easing],[callback]) This method toggles the visibility of the matching element by a height change.
FadeTo (Speed,opacity,[callback]) The method bars the opacity of the element in a gradual manner to the established value.
Fadetoggle (Speed,[easing],[callback]) This method toggles the visibility of the matching element by changing the opacity of the element.
Summary: animation methods
Hide () show (). FadeIn () FadeOut (), Slideup () Slidedown () FadeTo () Fadetoggle () Slidetoggle () aimate ()
Note: Aimate () is a method of custom animation. You can use him instead of all the other animation methods.