jquery怎么限制鼠标只能在div内移动?超过div的范围时,鼠标不能移动。
3条回答 默认 最新
- 崽崽的谷雨 2022-06-23 16:16关注
这个有点类似于 ,限制范围拖拽 。
也不知道 你是 想怎么限制 。是 移出就 提示还是什么 。
你或许 可以 改变思路 ,就是 移出 div 就 禁用鼠标 共能 这样也可以 。或者隐藏 鼠标 曲线 救国
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>js限制鼠标范围</title> <style> * { margin: 0; padding: 0; } .box { position: absolute; width: 100%; height: 100%; } .class { width: 400px; height: 400px; background: red; } </style> </head> <body> <div class="box"> <div class="class"> </div> </div> </body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> let box = document.getElementsByClassName("box")[0]; $(".class").mouseenter(function () { $("body").css({ "cursor": "auto" }); //显示鼠标 }); $(".class").mouseleave(function () { $("body").css({ "cursor": "none" }); //隐藏鼠标 // alert("移出") }); </script> </html>
https://blog.csdn.net/weixin_44599931/article/details/117073530
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效