当前位置: 首页 > news >正文

VUE PC端可拖动悬浮按钮

一、实现效果:

二、FloatButton.vue

<template><div><div class="sssss"><div class="callback float" @mousedown="down" @touchstart="down" @mousemove="move" @touchmove="move" @mouseover="over" @mouseout="out"@mouseup="end" @touchend="end" ref="fu" style="color: #1a1919;"><el-button circle @click="screen()">{{name}}</el-button></div></div></div>
</template><script>export default {name: "suspensionBall",props: {name: {type: String,default: '打开全屏'},},data() {return {left: 0,top: 40,bg: 1,menu: false,isLoading: false,flags: false, //控制使用position: {x: 0,y: 0,},nx: "",ny: "",dx: "",dy: "",xPum: "",yPum: "",movb: 1,num: 1,};},created() { },mounted() {this.left = this.$refs.fu.offsetLeft - 750;},methods: {out2() {this.menu = false;},over2() { },out() {this.bg = 2;},over() {this.menu = true;this.num = 2;this.bg = 1;},callback() {this.$router.go(-1);},onRefresh() {// window.location.reload();setTimeout((res) => {console.log(res);this.isLoading = false;}, 1000);},down() {this.flags = true;var touch;if (event.touches) {touch = event.touches[0];} else {touch = event;}this.position.x = touch.clientX;this.position.y = touch.clientY;this.dx = this.$refs.fu.offsetLeft;this.dy = this.$refs.fu.offsetTop;},move() {if (this.flags) {this.movb = 2;this.menu = false;var touch;if (event.touches) {touch = event.touches[0];} else {touch = event;}this.nx = touch.clientX - this.position.x;this.ny = touch.clientY - this.position.y;this.xPum = this.dx + this.nx;this.yPum = this.dy + this.ny;let width = window.innerWidth - this.$refs.fu.offsetWidth; //屏幕宽度减去自身控件宽度let height = window.innerHeight - this.$refs.fu.offsetHeight; //屏幕高度减去自身控件高度this.xPum < 0 && (this.xPum = 0);this.yPum < 0 && (this.yPum = 0);this.xPum > width && (this.xPum = width);this.yPum > height && (this.yPum = height);// if (this.xPum >= 0 && this.yPum >= 0 && this.xPum<= width &&this.yPum<= height) {this.$refs.fu.style.left = this.xPum + "px";this.$refs.fu.style.top = this.yPum + "px";this.left = this.xPum - 750;this.top = this.yPum;// }//阻止页面的滑动默认事件document.addEventListener("touchmove",function () {event.preventDefault();},false);}},//鼠标释放时候的函数end() {this.flags = false;},screen() {this.$emit("changeClick");},},};
</script>
<style scoped>.callback {position: fixed;width: 200px;height: 20px;background-repeat: no-repeat;background-size: 100% 100%;top: 200px;left: 90%;z-index: 99999;}.float {position: fixed;touch-action: none;text-align: center;border-radius: 24px;line-height: 48px;color: white;}.menuclass {text-align: left;position: absolute;color: #000;width: 764px;background: #ffffff;box-shadow: 0px 6px 26px 1px rgba(51, 51, 51, 0.16);padding: 20px;}.sssss {position: relative;background-color: #000;right: 0;z-index: 99999;}.titlea {font-size: 18px;font-family: Microsoft YaHei-Bold, Microsoft YaHei;font-weight: bold;color: #333333;}.boxa {display: flex;flex-wrap: wrap;margin-top: 20px;z-index: 999999;}.item {width: 168px;height: 75px;border-radius: 4px 4px 4px 4px;font-size: 16px;font-family: Microsoft YaHei-Bold, Microsoft YaHei;font-weight: bold;color: #ffffff;text-align: center;margin-left: 7px;line-height: 75px;}
</style>

三、父页面引用

<template><div><float-button ref="floatButton" :name="buttonName" @changeClick="screen" /></div>
</template><script>
import FloatButton from './chart/FloatButton'
export default {name: 'Index',components: {FloatButton},
}
</script>

相关文章:

  • 《统计学习方法:李航》笔记 从原理到实现(基于python)-- 第5章 决策树
  • 基于布谷鸟搜索的多目标优化matlab仿真
  • 微信小程序 安卓/IOS兼容问题
  • python爬虫3
  • 软件压力测试:探究其目的与重要性
  • 洛谷p1644跳马问题
  • 页面切换导致echarts不加载的问题
  • 【c语言】简单贪吃蛇的实现
  • Uboot中ARMV7和ARMV8 MMU配置
  • vscode git stash apply stash@{1}不生效
  • 基于python+django,我开发了一款药店信息管理系统
  • 【CSS】移动端适配
  • Echars3D 饼图开发
  • 部署实战--修改jar中的文件并重新打包成jar文件
  • stack和queue及优先级队列和适配器(包括deque)的介绍
  • [译]CSS 居中(Center)方法大合集
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • 345-反转字符串中的元音字母
  • ECMAScript入门(七)--Module语法
  • EventListener原理
  • happypack两次报错的问题
  • Java 11 发布计划来了,已确定 3个 新特性!!
  • k8s 面向应用开发者的基础命令
  • rc-form之最单纯情况
  • Redis字符串类型内部编码剖析
  • Service Worker
  • 缓存与缓冲
  • 前端js -- this指向总结。
  • 如何用vue打造一个移动端音乐播放器
  • gunicorn工作原理
  • k8s使用glusterfs实现动态持久化存储
  • Prometheus VS InfluxDB
  • 交换综合实验一
  • ​LeetCode解法汇总1276. 不浪费原料的汉堡制作方案
  • ​一文看懂数据清洗:缺失值、异常值和重复值的处理
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (ZT)薛涌:谈贫说富
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (机器学习-深度学习快速入门)第一章第一节:Python环境和数据分析
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (转)iOS字体
  • (转)编辑寄语:因为爱心,所以美丽
  • .equal()和==的区别 怎样判断字符串为空问题: Illegal invoke-super to void nio.file.AccessDeniedException
  • .MyFile@waifu.club.wis.mkp勒索病毒数据怎么处理|数据解密恢复
  • .NET 5.0正式发布,有什么功能特性(翻译)
  • .NET Framework与.NET Framework SDK有什么不同?
  • .net企业级架构实战之7——Spring.net整合Asp.net mvc
  • @ComponentScan比较
  • [\u4e00-\u9fa5] //匹配中文字符
  • [AutoSar NVM] 存储架构
  • [BZOJ] 2006: [NOI2010]超级钢琴
  • [HNOI2008]玩具装箱toy