Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ScreenX和ScreenY赢得';当浏览器进行屏幕缩放时,将元素与光标对齐_Javascript_Drag And Drop_Mouseevent - Fatal编程技术网

Javascript ScreenX和ScreenY赢得';当浏览器进行屏幕缩放时,将元素与光标对齐

Javascript ScreenX和ScreenY赢得';当浏览器进行屏幕缩放时,将元素与光标对齐,javascript,drag-and-drop,mouseevent,Javascript,Drag And Drop,Mouseevent,缩放屏幕时,MouseEvent的event.screenX和event.screenY与从顶部和底部的px偏移量不相等。放大时,它们会慢慢落在后面,放大时,它们会慢慢向前跳 如何考虑屏幕缩放以使元素跟随光标?诀窍是不要使用screenX和screenY,而是使用clientX和clientY。这些测量是相对于缩放的,也是相对于视口的(因此,如果代码嵌入到视口中,它们仍然有效)

缩放屏幕时,
MouseEvent
event.screenX
event.screenY
与从顶部和底部的px偏移量不相等。放大时,它们会慢慢落在后面,放大时,它们会慢慢向前跳


如何考虑屏幕缩放以使元素跟随光标?

诀窍是不要使用
screenX
screenY
,而是使用
clientX
clientY
。这些测量是相对于缩放的,也是相对于视口的(因此,如果代码嵌入到视口中,它们仍然有效)