JQuery (4)---Use MouseDown and MouseUp to easily determine if the mouse press and release position are the same

Source: Internet
Author: User
Tags data structures

In jquery, we can use MouseDown, MouseUp to track the mouse press and release events of the page.

How to get the position information of the mouse. The Pagex and Pagey properties of event events allow us to get the exact position of the mouse in the page, equivalent to the XY coordinates in the mathematical coordinate system.

So we can first use a global variable to record the location of the mouse position information, and then in the mouse release function to determine whether the position and release of the position is consistent, and then according to the results of the operation.

The sample code is as follows:

var x, y;
    $ (document). MouseDown (Event) {//Gets the position of the mouse pressed
        x = Event.pagex;
        y = event.pagey;
    });
    $ (document). MouseUp (function (event) {//mouse release
        var newx = Event.pagex;
        var newy = Event.pagey;
        if (x==newx && y==newy) {
            //Position same action
        }
        else{
            //position different operation
        }
    })

————————————————————————————————————————————————— – Java Architect Project Combat, high concurrency cluster distributed, big Data high availability video tutorials, total 760G

Download Address:

https://item.taobao.com/item.htm?id=562739965822

01. High Level architect 42 stages
02.Java Advanced System Training Architecture Course 148 hours
03.Java Advanced Internet Architect Course
04.Java Internet Architecture Netty, Nio, Mina, etc.-Video tutorial
05.Java Advanced Architecture Design 2016 finishing-video tutorial
06. Architect Foundation, advanced film
07.Java architect compulsory Linux operations series course
08.Java Advanced System Training Architecture Course 116 hours
+
Hadoop series tutorials, Java design patterns and data structures, Spring cloud microservices, Springboot Primer

—————————————————————————————————————————————————–

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.