Solve the same problem as the coordinates of the window obtained in the canvas

Source: Internet
Author: User

When using mouse events often want to get the current mouse x, y value, if the mouse event is a Window object, get the mouse x, Y is very simple, but when the mouse event is a window object, it is necessary to consider the position of the object in the window.

Because of the particularity of the canvas object, here I would like to analyze the problem of x, Y coordinates that need to be acquired when the mouse event is in the canvas object.

Here you need a method: Getboundingclientrect () to get the canvas of this rectangle object, if you want to know Getboundingclientrect () see http://jingyan.baidu.com/ Article/8cdccae960b041315413cdcd.html

Not much nonsense to say coding ....

<! DOCTYPE html>


Solve the same problem as the coordinates of the window obtained in the canvas

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.