简体   繁体   English

div的左上角是否始终在JavaScript中以0,0开头的坐标?

[英]Have top left corner of div always start the coordinates at 0,0 in javascript?

If I create a div tag with red color filled in at 300 x 300 pixels, I want to make it so that the coordinate system is 0,0 at the corner of the div tag instead of page. 如果我创建一个div标签,并用300 x 300像素填充红色,那么我想使其在div标签而不是页面的角处的坐标系为0,0。 So regardless of where the div tag is positioned, the top left corner of that div tag is always 0,0. 因此,无论div标签位于何处,该div标签的左上角始终为0,0。

If possible, it would be great if scrolling could be taken into account such that if I scroll down a bit, i can still click on the top left corner of the div and it would still know that it is the 0,0. 如果可能的话,最好考虑滚动,如果我向下滚动一点,我仍然可以单击div的左上角,它仍然会知道它是0,0。

It would involve something like: event.clientX and event.clientY or maybe there is a better method to accomplish this. 它将涉及到诸如:event.clientX和event.clientY,或者可能有更好的方法来完成此操作。

Are you meaning to do something like the following? 您是要执行以下操作吗?

<div style="position: fixed; top: 0px; left: 0px; width: 300px; height: 300px;">
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM