Getting started with jQuery: slideToggle () and bind () Methods

Source: Internet
Author: User

There were very few things learned yesterday, and some things were delayed. It was good today, And it entered the State in the morning. Although it was a bit cold, there was a catch of cold.

SlideToggle (speed, [callback]) in the sliding effect
Speed: Three predefined speeds ("slow", "normal", "fast") and millisecond values (for example, 1000) that indicate the animation duration)
[Callback] function executed when the animation is completed
Example:
Html: <p> This is the dddddddddddddddddddd used for testing. <br/>

Dddddddddddddddddddddddddddddddddddd <br/>

Ddddd </p>
$ (Document). ready (function (){
$ ("P"). slideToggle ("fast", function (){
Alert ("Animation Done .");
});
});
After reading it in the browser, it worked, and the line quickly slipped and disappeared.
If you add a style for this P label, style = "display: none", then this section will appear slowly, rather than disappear.

This disappears for no reason, and it is not very good. I suddenly remembered that I saw a bind () method yesterday and bound an event handler function to the element,
You can also use it to modify this method. Well, the effect is fine.
$ (Document). ready (function (){
$ ("P"). bind ("click", function (){
$ (This). slideToggle ("fast", function (){
Alert ("Animation Done .");
});
});
});
You can add a style without adding it. In short, this method is used.
Bind method details: bind an event processor function to a specific event (such as click) that matches each element.
This event handler receives an event object, which can be used to prevent (browser) default behavior. If
To cancel the default action and prevent event bubbles, the event handler function must return false.

Usage 1: The time processing function can be defined as an anonymous function.
$ ("P"). bind ("click", function (){
$ (This). slideToggle ("fast", function (){
Alert ("Animation Done .");
});
});
Usage 2: If an anonymous function cannot be defined, an optional data object can be passed as the second parameter, and the event processing function becomes the third parameter.
Function handler (event ){
Alert (event. data. foo );
}
$ ("P"). bind ("click", {foo: "bar"}, handler)
In fact, this bind method can cancel the default browser behavior and prevent event bubbles, because these two are not very familiar with, so do not write how
To solve these two problems, I plan to first check the browser's default behavior and event bubbles ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.