JQuery Mobile Touch Event Instance _jquery

Source: Internet
Author: User

The touch event is triggered when the user touches the screen (page).

The jquery library and the jquery Mobile library must be introduced as follows:

<script src= "Http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js" ></script>
<script src= "Http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js" ></script>

1.jQuery Mobile clicks

The Click event is triggered when the user clicks on the element.

The following example: When the <p> element is clicked, the current <p> element is hidden:

Copy Code code as follows:
<script>
$ (document). On ("Pagecreate", "#pageone", function () {
$ ("P"). On ("Tap", function () {
$ (this). Hide ();
});
});
</script>
<div data-role= "main" class= "Ui-content" >
<p> knock me down, I'll disappear. </p>
<p> knock me down, I'll disappear. </p>
<p> hit me and I'll disappear. </p>
</div>

2.jQuery Mobile clicks (Long Press)

Click on (Long Press) event to trigger after clicking (about one second)

Copy Code code as follows:
<script>
$ (document). On ("Pagecreate", "#pageone", function () {
$ ("P"). On ("Taphold", function () {
$ (this). Hide ();
});
});
</script>
<div data-role= "main" class= "Ui-content" >
<p> If you hit and hold it for a second, I'll disappear. </p>
<p> knock and hold on, I'll disappear. </p>
<p> knock and hold on and I'll disappear. </p>
</div>

3.jQuery Mobile Sliding

A slide event is an event that is triggered when a user is horizontally dragging more than 30PX in one second, or when an event that is less than 20px is dragged vertically:

Copy Code code as follows:
<script>
$ (document). On ("Pagecreate", "#pageone", function () {
$ ("P"). On ("Swipe", function () {
$ ("span"). Text ("Sliding detection!");
});
});
</script>
<div data-role= "main" class= "Ui-content" >
<p> slide in the text or box below. </p>
<p style= "border:1px solid black;height:200px;width:200px;" ></p>
<p><span style= "color:red" ></span></p>
</div>

4.jQuery Mobile slide to the left

Sliding left event triggers when the user drags an element greater than 30px to the left:

Copy Code code as follows:
<script>
$ (document). On ("Pagecreate", "#pageone", function () {
$ ("P"). On ("Swipeleft", function () {
Alert ("You slide to the left!");
});
});
</script>
<div data-role= "main" class= "Ui-content" >
<p style= "border:1px solid black;margin:5px;" > Slide to the left-don't go beyond the border! </p>
</div>

5.jQuery Mobile Slide Right

Slide the event to the right when the user drags an element greater than 30px to the right:

Copy Code code as follows:
<script>
$ (document). On ("Pagecreate", "#pageone", function () {
$ ("P"). On ("Swiperight", function () {
Alert ("Slide right!");
});
});
</script>
<div data-role= "main" class= "Ui-content" >
<p style= "border:1px solid black;margin:5px;" > Slide Right-don't go beyond the border! </p>
</div>

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.