How to use the mobile JQ plug-in hammer _ jquery

Source: Internet
Author: User
This article introduces the jQuery plug-in Hammer on the Mobile End. js, an open-source and lightweight javascript library that can recognize touch without relying on other things. mouse events support various mobile phone events, such as scaling, qq left slide Delete, zoom in, rotate and so on from pc end to Mobile End believe that many front-end siege engineers worried about the mobile end, It is very laborious to write the original sound of mobile terminal events, the jq click has a latency of 300 milliseconds. Now we have a good jq plug-in hammer and Hammer. javascript is an open-source and lightweight javascript library that can recognize the touch without relying on other things. mouse events support various mobile phone events, such as scaling and left-sliding qq deletion, zoom in and rotate.

Next we will use a tab switch to introduce hammer.

Usage:

1. First introduce jq2.0 and later versions and jquery. hammer. js.

2. Get the element. Just like jq, add hammer to the end and var hammertime = $ ('. tabs A'). hammer ();

3. You can directly add the event hammertime. on ('Tap ', function (ev) {} using the tap Click Event in hammer. Function can write your own js.

Hammer. dragstart = function (ev) {}; // start to drag hammer. drag = function (ev) {}; // drag hammer. dragend = function (ev) {}; // drag and end hammer. onswipe = function (ev) {}; // sliding hammer. tap = function (ev) {}; // click hammer. doubletap = function (ev) {}; // double-click hammer. hold = function (ev) {}; // long press hammer. release = function (ev) {}; // exit the screen with your finger

Experience link: http://hammerjs.github.io/

Js code

$ (Function () {var hammertime = $ ('. tabs '). hammer (); hammertime. on ('tap', function (ev) {$ (this ). addClass ('actives '). siblings (). removeClass ('actives'); // Add a class to remove at the same level. Var index = $ ('. tabs '). index (this); // index $ ('. tab-bott '). eq (index ). show (). siblings (). hide ();})})

The above is all the content of this article. I hope you will like it.

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.