Home > Article > Web Front-end > JS delayer
The content introduced in this article is the code of js delayer. Now I share it with everyone. Friends in need can refer to it
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" type="text/css" href="系统CSS初始化.css"> <style> #p1{ width: 50px; height: 50px; background: rebeccapurple; float: left; margin: 20px; } #p2{ width: 200px; height: 200px; background: #555555; float: left; margin: 20px; display: none; } </style> <script> window.onload=function () { var op1=document.getElementById("p1"); var op2=document.getElementById("p2"); var timer=null; op1.onmousemove=function () { clearTimeout(timer); op2.style.display="block"; } op1.onmouseleave=function () { timer= setTimeout(function () { op2.style.display="none"; },500) } op2.onmousemove=function () { clearTimeout(timer); } op2.onmouseleave=function () { timer=setTimeout(function () { op2.style.display="none"; },500) } } </script> </head> <body> <p id="p1";></p> <p id="p2"></p> </body> </html>
##
The above is the detailed content of JS delayer. For more information, please follow other related articles on the PHP Chinese website!