Vue 可拖动导航栏

发布于 2023-10-06 09:37:36 字数 2536 浏览 32 评论 0

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

清君侧

暂无简介

文章
评论
27 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文