鼠标拖拽拖动盒子时,与盒子内某些点击事件冲突问题解决

目录

  • 问题
  • 解决思路
  • 解决代码(标注【主要代码】的为重点)

问题

拖动该悬浮球时,鼠标弹起可能会触发悬浮球内事件
在这里插入图片描述

解决思路

  • 鼠标拖动盒子时,将 isMove 设为 true 意为正在拖动盒子,此时将 class="btns_move" 遮挡容器展示在悬浮球上层,以覆盖悬浮球,此时也就不存在触发悬浮球点击事件的冲突了;鼠标拖动完盒子弹起时再将 isMove 设为 false 意为不在拖动盒子(遮挡容器 class="btns_move" 不存在),可以触发悬浮球点击事件
  • 【注解】click 点击事件主要是在鼠标弹起时触发class="btns_move" 容器展示时,鼠标已不再悬浮器上点击,所以也就不存在鼠标在悬浮球上弹起的说法,因此可解决拖动盒子时与悬浮球点击事件冲突的问题
    在这里插入图片描述

解决代码(标注【主要代码】的为重点)

index.vue

<div ref="btns" class="btns" @mousedown="mousedownHandler"><div class="btns_other_police" @click="$refs.SearchDialogRef.open('police')"><img :src="require(`@/assets/portrait/iconfont/${theme}_police.png`)" /><span>其他警员</span></div><div class="btns_fullscreen_show" @click="handleScreenFull"><img :src="require(`@/assets/portrait/iconfont/${theme}_expand.png`)" /><span> {{ isFullscreen ? '退出全屏' : '全屏显示' }} </span></div><!-- <div v-show="isMove" class="btns_move">我是避免拖动盒子与盒子内事件冲突的元素</div> --><div v-show="isMove" class="btns_move" />  <!-- 【主要代码】 -->
</div>

index.scss

.btns {$btnWiddth: 70px;position: absolute;bottom: 10px;right: 10px;// z-index: 9999;z-index: 2000;width: $btnWiddth;height: 147px;cursor: move;opacity: 0.8;&_other_police,&_fullscreen_show {width: $btnWiddth;height: $btnWiddth;display: flex;flex-direction: column;align-items: center;justify-content: center;// background-color: red;border-radius: 50px;font-size: 12px;cursor: pointer;img {width: 25px;height: 25px;margin-bottom: 5px;}}&_other_police {margin-bottom: 7px;}&_move {width: 100%;height: 100%;// background-color: red;position: absolute; /* 【主要代码】 */top: 0;// z-index: -10;}
}

mixins/index.js

import { mapGetters } from 'vuex'
import screenfull from 'screenfull'
import portraitMock from '../../../../public/static/portraitMock.json'export const PortraitMixin = {data() {return {lightEchartsNoDataColor: '#000',blueEchartsNoDataColor: '#fff',timeFormat: 'yyyy/MM/dd',timeValueFormat: 'yyyy-MM-dd',portraitMock,initBtnX: 0,initBtnY: 0,isMove: false // 【主要代码】}},computed: {...mapGetters(['isFullscreen'])},mounted() {const _this = thiswindow.addEventListener('resize',() => {// 全屏下监控是否按键了ESCif (_this.checkFull()) {// 全屏下按键esc后要执行的动作screenfull.exit()_this.$store.commit('SET_isFullscreen', false)}},false)document.addEventListener('mouseup', () => {this.isMove = false // 【主要代码】document.removeEventListener('mousemove', this.mousemoveHandler)})},filters: {noDataFilter(val) {return val || val === 0 ? val : '-'},numFilter(val) {return val || val === 0 ? Number(val).toLocaleString() : '-'},bmQlfFilter(val, color, key) {const data = val.filter((item) => item.policeColorCode.includes(color))return data.length ? (data[0][key] || data[0][key] === 0 ? data[0][key] : '-') : '-'}},methods: {// 全屏显示handleScreenFull() {if (!screenfull.isEnabled) {this.$message({message: 'you browser can not work',type: 'warning'})return false}if (this.isFullscreen) {screenfull.exit()this.$store.commit('SET_isFullscreen', false)this.$store.commit('SET_isShowHeader', true)} else {screenfull.request()this.$store.commit('SET_isFullscreen', true)this.$store.commit('SET_isShowHeader', false)}},/*** 是否全屏并按键ESC键的方法*/checkFull() {const isFullscreen =window.fullScreen ||window.isFullscreen ||document.webkitIsFullScreen ||document.msFullscreenEnabledlet isFull = document.fullscreenEnabled && !isFullscreen// to fix : false || undefined == undefinedif (isFull === undefined) {isFull = false}return isFull},toDetailHandler(type) { // 该方法和此处无关if (type === 'zffx') {this.$router.push({path: '/warning-manage-common/warning-query',query: {date: JSON.stringify({kssj: this.zffxSearchTime[0],jssj: this.zffxSearchTime[1]}),...(this.searchXm ? { zrr: this.searchXm } : {}),...(this.searchBm ? { ssbm: this.searchBm } : {})}})}},mousedownHandler($event) {this.initBtnX = $event.pageX - this.$refs.btns.offsetLeftthis.initBtnY = $event.pageY - this.$refs.btns.offsetTopdocument.addEventListener('mousemove', this.mousemoveHandler)},mousemoveHandler($event) {this.isMove = true // 【主要代码】this.$refs.btns.style.left = $event.pageX - this.initBtnX + 'px'this.$refs.btns.style.top = $event.pageY - this.initBtnY + 'px'}}
}

解决效果
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/115491.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

采用cv2和默认的人脸识别分类器实现人脸检测功能

人脸识别分类器 haarcascade_frontalface_default 提示&#xff1a;分类器文件地址在这里&#xff1a;https://github.com/opencv/opencv/blob/687fc11626901cff09d2b3b5f331fd59190ad4c7/data/haarcascades/haarcascade_frontalface_default.xml 文章目录 人脸识别分类器 haar…

终于把量化入门了,实盘权限已开,学习这件事也不难

多数人18岁就死了&#xff0c;但直到75岁才埋。 ——网易云热评《杀死那个石家庄人》 猫猫挺喜欢这句话的&#xff0c;为什么只活动75岁&#xff0c;于是我查了查现如今78.6岁&#xff0c;大差不差的。 那扣扣减减&#xff0c;人生短短57年&#xff0c;唯一十八岁那年&#xff…

C# 查找迷宫路径

1.导入图像&#xff0c;并且将图像转灰度 using var img new Image<Bgr, byte>(_path); using var grayImg img.Convert<Gray, byte>(); 2.自动二值化图像 using var inputGrayOut new Image<Gray, byte>(grayImg.Size); // 计算OTSU阈值 var threshol…

[正确重装docker] Win10 重装 Docker 提示 Exising installation is up to date 的正确姿势

Win10 重装 Docker 报错 Exising installation is up to date 的一种情况是原来的 docker 没有卸载干净&#xff0c;或者说&#xff0c;没有正确卸载。 巧了&#xff0c;我就是直接删除了&#xff0c;因为一些原因重装了好几次&#xff0c;血泪史留给各位嘲笑。 一条正确的卸…

怎么将几张图片做成pdf合在一起

怎么将几张图片做成pdf合在一起&#xff1f;在我们平时的工作中&#xff0c;图片和pdf都是非常重要的电脑文件&#xff0c;使用也非常频繁&#xff0c;图片能够更为直观的展示内容&#xff0c;而pdf则更加的正规&#xff0c;很多重要文件大多会做成pdf格式的。在职场人的日常工…

力扣刷题-数组-螺旋矩阵

模拟过程&#xff0c;但却十分考察对代码的掌控能力。 重点&#xff1a;循环不变量原则&#xff01; 第一条原则&#xff1a; 模拟顺时针画矩阵的过程&#xff1a; 填充上行从左到右填充右列从上到下填充下行从右到左填充左列从下到上 由外向内一圈一圈这么画下去。 第二条原…

如何在没有第三方.NET库源码的情况,调试第三库代码?

大家好&#xff0c;我是沙漠尽头的狼。 本方首发于Dotnet9&#xff0c;介绍使用dnSpy调试第三方.NET库源码&#xff0c;行文目录&#xff1a; 安装dnSpy编写示例程序调试示例程序调试.NET库原生方法总结 1. 安装dnSpy dnSpy是一款功能强大的.NET程序反编译工具&#xff0c;…

ESP8266 WiFi物联网智能插座—电能计量

目录 1、芯片功能 2、性能指标 3、寄存器说明 4、UART通信协议 4.1、写操作帧格式和时序 4.2、读操作帧格式和时序 4.3、读取全电参数数据包 4.4、配置波特率 4.5、UART保护机制 5、功能说明 5.1、电流电压瞬态波形计量 5.2、有功功率 5.3、有功功率防潜动 5.4、电能计量 5.5、…

摩尔信使MThings实用功能盘点

“冗长的用户手册”与“精简的交互设计”之间势必产生一条信息鸿沟&#xff0c;现在就来盘点一下摩尔信使MThings有哪些隐蔽而实用的功能。 01 数据配置类 一键刷新 功能&#xff1a;快速读取所有位数据、寄存器数据的当前数值。 操作&#xff1a;双击“数值”列表头。 一键…

基于微信小程序的公司后勤服务(设备)系统设计与实现(源码+lw+部署文档+讲解等)

文章目录 前言运行环境说明员工微信端的主要功能有&#xff1a;管理员的主要功能有&#xff1a;具体实现截图详细视频演示为什么选择我自己的网站自己的小程序&#xff08;小蔡coding&#xff09;有保障的售后福利 代码参考论文参考源码获取 前言 &#x1f497;博主介绍&#x…

【C++】搜索二叉树底层实现

目录 一&#xff0c;概念 二&#xff0c;实现分析 1. 插入 &#xff08;1.&#xff09;非递归版本 &#xff08;2.&#xff09;递归版本 2. 打印搜索二叉树 3.查找函数 &#xff08;1.&#xff09;非递归版本 &#xff08;2.&#xff09;递归版本 4. 删除函数&#x…

第一百五十一回 自定义组件综合实例:游戏摇杆二

文章目录 内容回顾实现方法位置细节示例代码我们在上一章回中介绍了如何实现 游戏摇杆相关的内容,本章回中将继续介绍这方面的知识.闲话休提,让我们一起Talk Flutter吧。 内容回顾 我们在上一章回中介绍了游戏摇杆的概念以及实现方法,并且通过示例代码演示了实现游戏摇杆的…