Vue 可拖动导航栏
<template> <div> <header> <span>Vue.js PWA</span> </header> <main> <div class="tags" @dragover="dragover" @drop="drop"> <div class="items" draggable="true" @dragstart="dragStart" :style="{left: currentPos + 'px'}"> <div class=""> <a href="">音乐</a> <a href="">科技</a> <a href="">文化</a> <a href="">美食</a> <a href="">摄影</a> <a href="">动物</a> <a href="">旅游</a> <a href="">读书</a> <a href="">电子</a> <a href="">外语</a> </div> </div> </div> </main> </div> </template> <script> /* eslint-disable no-console */ import Hello from './components/Hello'; export default { name: 'app', data() { return { initPos: 0, originPos: 0, deltaX: 0, currentPos: 0, }; }, methods: { dragStart(e) { e.dataTransfer.dropEffect = 'move'; this.originPos = e.clientX; }, drag(e) { console.log(e); }, dragover(e) { console.log(e); this.deltaX = e.clientX - this.originPos; this.originPos = e.clientX; this.currentPos = this.initPos + this.deltaX; this.initPos = this.currentPos; }, drop(e) { console.log(e); }, }, components: { Hello, }, }; </script> <style> .tags { width: 500px; border: 1px solid rgba(0, 0, 0, 0.1); margin: 0 auto; overflow-x: hidden; } .tags .items { width: 1000px; display: flex; position: relative; } .tags a { display: inline-block; text-decoration: none; color: #444; padding: 5px 10px; } body { margin: 0; } #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; color: #2c3e50; } main { text-align: center; margin-top: 40px; } header { margin: 0; height: 56px; padding: 0 16px 0 24px; background-color: #35495E; color: #ffffff; } header span { display: block; position: relative; font-size: 20px; line-height: 1; letter-spacing: .02em; font-weight: 400; box-sizing: border-box; padding-top: 16px; } </style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论