Giter Club home page Giter Club logo

vue-floating-menu's Introduction

Vue-Floating-Menu

Netlify Status

前言

正如这个名字,这是一个具有拖拽吸附功能的浮窗菜单,开源项目

一个基于 vue 的浮窗组件,可在屏幕内自由拖拽,拖拽后可以根据最后的位置吸附到页面两边,而且可以点击浮窗显示菜单

附上 github 项目地址 vue-floating-menu

效果如下: vue-floating-menu

遇到的问题总结

  • 鼠标移动过快,导致拖拽失焦:
<div @mousedown.stop.prevent="moveStart" @click.stop.prevent="toggleMenu"></div>
moveStart(e) {
  // ... ...省略号... ...
  // 具体可以在github项目里查看

  document.onmousemove = async (e) => {
    this.clickFlag = false;
    this.moveFlags = true;
    // 💥👉在这里边处理拖拽时的位置更新,就是因为这个。
    // 我之前是单独通过监听mousemove的方法,所以遇到了这个问题
  };
  document.onmouseup = () => {
    document.onmousemove = null;
    document.onmouseup = null;
    this.moveEnd();
  };
},
  • 判断是否是点击事件:
<div @mousedown.stop.prevent="moveStart" @click.stop.prevent="toggleMenu"></div>
toggleMenu() {
  //  如果上一次down事件到下一次click事件中 相同即为点击事件
  if (this.lastMoveIndex == this.curMoveIndex) {
	//💥点击事件
  }
  this.curMoveIndex = this.lastMoveIndex;
},
moveStart(e) {
  // ... ...省略号... ...
  // 具体可以在github项目里查看
  document.onmousemove = async (e) => {
    this.lastMoveIndex++;
  };
  document.onmouseup = () => {
    document.onmousemove = null;
    document.onmouseup = null;
    this.moveEnd();
  };
},

Usage

Demo see here: https://vue-floating-menu.netlify.app

  • 添加菜单的方式:
    组件 src/components/menuPart.vue 是添加菜单的 demo

如果vue-floating-menu觉得不错的,记得给个 ⭐ 哟

Edit Vue Floating Menu Examples

vue-floating-menu's People

Contributors

yuanzhou3118 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.