screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Get Element Position</h3> <div ref="myElement">This is my element</div> <pre>Top:{{top}}</pre> <pre>Right:{{right}}</pre> <pre>Bottom:{{bottom}}</pre> <pre>Left:{{left}}</pre> <pre>Height:{{height}}</pre> <pre>Width:{{width}}</pre> </div> <script type="module"> const app = Vue.createApp({ data() { return { top: '', bottom: '', left: '', right: '', width: '', height: '', } }, mounted() { const el = this.$refs.myElement; const rect = el.getBoundingClientRect(); this.top = rect.top; this.bottom = rect.bottom; this.left = rect.left; this.right = rect.right; this.width = rect.width; this.height = rect.height; } }) app.mount('#app') </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } #app div { background-color: #f2f2f2; border-radius: 0.5rem; padding: 1rem; color: blue; font-size: 20px; margin: 1rem; } pre { font-size: 1.2rem; color: #333; background-color: #f7f7f7; padding: 0.5rem; margin: 0.5rem; border-radius: 5px; } </style> </body> </html>