mousedown和blur配合使用时,ie6/7/8的bug

本文探讨了mousedown事件在不同浏览器中对于输入框焦点的影响。在现代浏览器中,此事件可能会导致输入框失去焦点,但可以通过阻止默认行为来避免。然而,在IE6/7/8中,即便阻止默认行为,焦点丢失的问题仍然存在。
<script> document.addEventListener('DOMContentLoaded', (event) => { const images = document.querySelectorAll('img'); images.forEach((image) => { image.addEventListener('click', (event) => { var original_image = document.getElementById("new_image"); if (image.alt != 'no'){ reset_image(); original_image.src = image.src; document.getElementById('image-background').style.cssText='display:block;display: flex;'; } }); }); }); </script> <style> #image-background{ top: 0px; left: 0px; width: 100%; z-index: 95; height: 100%; display: none; height: 100vh; position: fixed; overflow: hidden; align-items: center; justify-content: center; background-color: rgba(0,0,0,0.75); -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } #image-background img { cursor: grab; max-width: 100%; max-height: 100%; border-radius: 8px; -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } #image-background button { border: none; color: black; font-size: 16px; margin: 4px 2px; cursor: pointer; font-size: 18px; overflow: hidden; padding: 15px 26px; text-align: center; align-items: center; border-radius: 10px; text-decoration: none; justify-content: center; display: inline-block; backdrop-filter: blur(6px); font-family: 'Microsoft Yahei'; background-color: rgba(255, 255, 255, 0.5); -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } #image-background button:hover { box-shadow: 0 0 8px rgba(0, 0, 255, 0.6),0 0 16px rgba(0, 0, 255, 0.4), 0 0 32px rgba(0, 0, 255, 0.2); -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } .image-background_close{ top: 10px; right: 12.5px; font-size: 40px; position: fixed; font-weight: bold; padding: 2px 20px; background-color: none; color: rgba(255,255,255,0.75); -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } .image-background_close:hover{ cursor: pointer; border-radius: 6px; text-decoration: none; color: rgba(255,255,255,1); background-color:rgba(0,0,0,0.5); -webkit-transition-duration: 0.2s; transition-duration: 0.2s; } </style> <script> function demo(e){ if(e.wheelDelta){ if(e.wheelDelta > 0){ zoomIn(); } if(e.wheelDelta < 0){ zoomOut(); } } } window.addEventListener("mousewheel",demo) </script> <div id="image-background"> <span style="font-size:22px;font-family:'Microsoft Yahei';background-color:rgba(0,0,0,0.2);padding:10px 20px;border-radius:4px;color:white;top:10px;left:12.5px;position:fixed;z-index:9999;"> 图片预览 </span> <img style="position: absolute;"id="new_image"> </br> <div align="center"style="position:fixed;bottom:0;width:100%;"> <span class="image-background_close"onclick="document.getElementById('image-background').style.cssText='display:none';"> × </span> <button onclick="zoomIn()"> 放大图片 </button> <button onclick="zoomOut()"> 缩小图片 </button> <button onclick="rotateClockwise()"> 顺针旋转90° </button> <button onclick="counterclockwiseRotation()"> 逆针旋转90° </button> <button onclick="reset_image()"> 1:1 </button> <button onclick="window.open(new_image.src);"> 在新窗口打开图片 </button> <button onclick="information()"> 查看图片信息 </button> </div> </div> <script> function reset_image(){ scale = 1; rotateAngle = 0; var image_number = document.getElementsByTagName('img'); var image_number = image_number.length - 1; var img = document.getElementById('new_image'); document.getElementById('new_image').style.transform = `scale(${scale})`; document.getElementById('new_image').style.transform = `rotate(${rotateAngle}deg) scale(${scale})`; img.style.top = '50%'; img.style.left = '50%'; img.style.transform = 'translate(-50%, -50%)'; } function zoomIn() { scale += 0.1; document.getElementById('new_image').style.transform = `rotate(${rotateAngle}deg) scale(${scale})`; } function zoomOut() { scale -= 0.1; if(scale < 0.1){ scale = 0.1; return false; } else{ document.getElementById('new_image').style.transform = `rotate(${rotateAngle}deg) scale(${scale})`; } } function rotateClockwise() { rotateAngle += 90; document.getElementById('new_image').style.transform = `rotate(${rotateAngle}deg) scale(${scale})`; } function counterclockwiseRotation() { rotateAngle -= 90; document.getElementById('new_image').style.transform = `rotate(${rotateAngle}deg) scale(${scale})`; } function information(){ alert( "<span style='color:lightblue;'><b>["+new_image.width+"×"+new_image.height+"]</b></span>图片<b>信息</b></span>", "<img src="+new_image.src+"></br></br><p style='font-size:18px;color:black'>图片宽度:<b>"+new_image.width+"</b></br>图片高度:<b>"+new_image.height+"</b></br>图片格式:<b>"+new_image.src.substr(new_image.src.lastIndexOf(".")+1)+"</b></br>路径:<a href='"+new_image.src+"'>"+new_image.src+"</a></br><span>"+new_image.title+"</span>", "关闭<b>图片信息</b>" ) } </script> <img src="80cf53f3-168e-4.png"> <script type="text/javascript"> window.onload = function(){ var new_image = document.getElementById("new_image"); move(new_image); }; function move(obj){ obj.onmousedown = function(event){ obj.setCapture && obj.setCapture(); event = event ||window.event var ol = event.clientX -obj.offsetLeft; var ot = event.clientY - obj.offsetTop; document.onmousemove = function(event){ event = event ||window.event var left = event.clientX-ol; var top = event.clientY-ot; obj.style.left = left+"px"; obj.style.top = top+"px"; }; document.onmouseup = function(){ document.onmousemove = null; document.onmouseup = null; obj.releaseCapture && obj.releaseCapture(); }; return false; }; }; </script> 以上代码中,拖拽功能有bug,拖动之后会恢复到中心位置,而且不能支持放大、旋转后拖动,修复上面的代码存在的bug
07-03
在 AntV X6 2.17.1 版本中,`graph.history.startBatch()` `graph.history.stopBatch()` 的作用是将多个操作合并为一次历史记录,从而在撤销(undo)重做(redo)作为一个整体处理。在 `mousedown`、`mousemove` `mouseup` 等事件中使用,需要特别注意操作的上下文一致性以及事件流的完整性。 由于 `mousemove` 事件可能频繁触发,建议在 `mousedown` 调用 `startBatch()`,在 `mouseup` 调用 `stopBatch()`,以确保整个交互过程中的所有操作都被视为一个批次。以下是一个典型的使用模式: ```typescript let isDragging = false; graph.on('node:mousedown', () => { graph.history.startBatch(); isDragging = true; }); graph.on('cell:mousemove', (e) => { if (isDragging) { // 执行拖动相关的操作,例如移动节点 const node = e.cell; node.position(e.x, e.y); } }); graph.on('canvas:mouseup', () => { if (isDragging) { graph.history.stopBatch(); isDragging = false; } }); ``` 需要注意的是,如果在 `mousemove` 中执行了异步操作或涉及 Vue 的响应式更新,应确保这些操作不会破坏 `batch` 上下文。例如,在 Vue 项目中,若使用了 Vue 2.7 或 Vue 3 的响应式 API(如 `reactive` 或 `ref`),需确保 AntV X6 插件与 Vue 实例的版本兼容,否则可能导致历史记录功能异常[^3]。 此外,若在 `batch` 中嵌套了多个 `startBatch` `stopBatch` 调用,应确保它们的嵌套结构正确,避免出现不匹配的调用导致上下文混乱。AntV X6 的 `history` 模块支持嵌套的 `batch` 操作,但建议在最外层统一控制批次的开始结束。 ### 相关问题 1. AntV X6 中如何监听 history 的撤销重做事件? 2. AntV X6 中如何自定义 history 的最大记录条目数? 3. 在 AntV X6 中,如何在执行 batch 操作嵌套其他 batch 操作?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值