运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <title>Mouse Pointer Position</title> <style> #app { border: black dashed 1px; width: 200px; padding: 0 20px 20px 20px; } #app > div { width: 160px; height: 80px; background-color: lightcoral; padding: 20px; } #app span { font-weight: bold; font-family: 'Courier New', Courier, monospace; } </style> </head> <body> <h1>Example: Mouse Pointer Position</h1> <div id="app"> <p>Move the mouse pointer over the box below:</p> <div v-on:mousemove="mousePos"> <span>xPos: {{ xPos }}</span><br><span>yPos: {{ yPos }}</span> </div> </div> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script> const app = Vue.createApp({ data() { return { xPos: 0, yPos: 0 } }, methods: { mousePos(event) { this.xPos = event.offsetX this.yPos = event.offsetY } } }) app.mount('#app') </script> </body> </html>