Home >
Web Front-end >
JS Tutorial >
Differences between event.x, event.clientX, event.offsetX_javascript skills
Differences between event.x, event.clientX, event.offsetX_javascript skills
WBOY
Release: 2016-05-16 19:24:30
Original
1276 people have browsed it
x: Sets or gets the position of the mouse on the x coordinate relative to the outer boundary of the parent element of the target event. clientX: The x coordinate position relative to the client area, excluding the scroll bar, is the text area. offsetx: Set or get the position of the mouse on the x coordinate relative to the inner boundary of the parent element of the target event. screenX: relative to the user screen. Test code one: [code]
<script> <br>function window.onbeforeunload() <br>{ <br>alert('event.clientX=' event.clientX );//If the mouse clicks the "Refresh" button, it is related to the position of the mouse click <br>alert('event.offsetX=' event.offsetX); <br>alert('document.body.clientWidth=' document.body.clientWidth); <br>alert('event.clientY=' event.clientY); <br>alert('event.offsetY=' event.offsetY); <br>alert('event.altKey=' event.altKey); <br>if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey) <br>{ <br>window.event.returnValue="Are you sure you want to exit this page? "; <br>}else <br>{ <br>alert("You are refreshing"); <br>} <br>} <br></script> [/html] Demo Code 2:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn