Implementation of the tap event in zepto. js to prevent bubbling

Source: Internet
Author: User

Implementation of the tap event in zepto. js to prevent bubbling

This article mainly introduces the implementation method of the tap event in zepto. js to prevent bubbling. The example analyzes the solution to the click latency caused by bubbling. For more information, see

 

 

The example in this article describes how the tap event in zepto. js blocks bubbles. Share it with you for your reference. The details are as follows:

Recently, I was working on a Mobile website that wanted to use jQuery Mobile, but the file was too large, so I used zepto. js.

Because the use of the click Event in mobile Web pages has a delay, the tap event in zepto. js is used.

You can use stopPropagation to prevent bubbling by using the click event, but this method is not valid for the tap.

Now I need to achieve this effect: Click the. btn button and display div. panel. When I click non-div. panel, hide div. panel.

?

1

2

3

4

5

6

7

$ ("A. btn"). on ("tap", function (e ){

E. stopPropagation (); // This method does not work

$ ("Div. panel"). show ();

});

$ (Document). on ("tap", function (e ){

$ ("Div. panel"). hide ();

});

Through the debugging tool, we can get that the object e has a target attribute, so we can use this attribute to achieve the desired effect:

?

1

2

3

4

5

6

7

8

$ ("A. btn"). on ("tap", function (){

$ ("Div. panel"). show ();

});

$ (Document). on ("tap", function (e ){

If (! Attributes (e.tar get). hasClass ("btn ")){

$ ("Div. panel"). hide ();

}

});

This solves the problem.

I hope this article will help you design javascript programs.

Related Article

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.