admin管理员组文章数量:1425195
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. So regardless of where the div tag is positioned, the top left corner of that div tag is always 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.
It would involve something like: event.clientX and event.clientY or maybe there is a better method to acplish this.
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. So regardless of where the div tag is positioned, the top left corner of that div tag is always 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.
It would involve something like: event.clientX and event.clientY or maybe there is a better method to acplish this.
Share Improve this question asked May 18, 2011 at 14:36 RevieraReviera 11 silver badge2 bronze badges 3-
Can you not make the 300x300 div wrap all of your content and position all of the children using
relative
? – Doug Stephen Commented May 18, 2011 at 14:38 - The concept I would like to apply to table as well, like: if I had two rows in a table, and i made the first row a height of 30pixels. The second row contains the div. I want to be able to mouseover/click the top left corner of the row and have it be 0,0. The method to do this I think involves attaching the mouse event listener to the div, but im not sure what the syntax would be. – Reviera Commented May 18, 2011 at 14:39
- The answer to this question might help you. – Jeremy Commented May 18, 2011 at 14:40
1 Answer
Reset to default 3Are you meaning to do something like the following?
<div style="position: fixed; top: 0px; left: 0px; width: 300px; height: 300px;">
</div>
本文标签:
版权声明:本文标题:html - Have top left corner of div always start the coordinates at 0,0 in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745415398a2657660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论