运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> div {border:1px solid red; height:300px;} span {font-size:30px;} </style> <body> <h1>Mouse Events</h1> <h2>The offsetY Property</h2> <p>The offsetY property returns the y-coordinate the mouse cursor, relative to the target element.</p> <p>In this example, the red DIV is the target element.</p> <p>Click inside the red DIV element:</p> <div onclick="myFunction(event)" style="border:2px solid red;height:100px"></div> <p id="demo"></p> <script> function myFunction(event) { let y = event.offsetY; document.getElementById("demo").innerHTML = "The y-coordinate is: " + y; } </script> </body> </html>