其他17---解决onmouseover多次触发问题
2022/4/1 6:19:34
本文主要是介绍其他17---解决onmouseover多次触发问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .bo{ width:100%; background-color: #7fffd4; transition:top 1.5s; } </style> </head> <body> <div class="box"> <div class="box1" style="position:relative;width:500px;height:300px;border:1px solid red;overflow: hidden;"> <img src="./image/4.jpg" alt="" style="width:500px;height:300px;"> <div style="position:absolute;top:240px;background-color: bisque;" class="bo"> <h3>你好明天</h3> <p>你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天你好明天</p> </div> </div> </div> <script> var item=document.getElementsByClassName('box1')[0] var bo=document.getElementsByClassName('bo')[0] item.onmouseover = function(ev) { var ev=ev||window.event; if(!isMouseLeaveOrEnter(ev,this)){return false;} bo.style.top=0+'px' }; item.onmouseout = function(ev) { var ev=ev||window.event; if(!isMouseLeaveOrEnter(ev,this)){return false;} bo.style.top=240+'px' }; //消除onmouseover和onmouseout重复执行,这是关键代码 function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); } </script> </body> </html>
这篇关于其他17---解决onmouseover多次触发问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)