本篇文章介绍的内容是js的延时器的代码,现在分享给大家,有需要的朋友可以参考一下
<!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>
Atas ialah kandungan terperinci JS的延时器 . Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!