Home > Web Front-end > JS Tutorial > body text

How to implement delay hiding function through JS

亚连
Release: 2018-06-14 16:42:31
Original
1651 people have browsed it

Below I will share with you a JS method to implement the delayed hiding function (similar to QQ avatar mouse placement to display information), which has a good reference value and I hope it will be helpful to everyone.

JS implements delayed hiding

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>延迟隐藏</title>
 <style>
 #p1{
  width:100px;
  height:100px;
  background:yellow; 
  border: 5px solid #999;
  border-radius: 10px;
  position: absolute;
  right: 50px;
  text-align: center;
  line-height: 100px;
  margin-bottom:10px;
 }
 #p2{
  width:200px;
  float: left;
  height:200px;
  border: 5px solid #999;
  border-radius: 10px;
  position: absolute;
  right:160px;
  text-align: center;
  line-height: 200px;
  background:green;
  display:none;
 }
</style>

<script>
 window.onload=function(){
  var p1=document.getElementById("p1");
   p1.innerHTML="鼠标请放上!";
  var p2=document.getElementById(&#39;p2&#39;);
   p2.innerHTML="鼠标请移开!";
  var timer=null;
  p1.onmouseover= function(){  
    clearTimeout(timer);
    p2.style.display=&#39;block&#39;;
  };
   p1.onmouseout= function(){
   clearTimeout(timer);
    timer= setTimeout(function(){
      p2.style.display=&#39;none&#39;;
    }, 700);
  };
  p2.onmouseover=function(){
   clearTimeout(timer);
  };
  p2.onmouseout=function(){
   clearTimeout(timer);
    timer=setTimeout(function(){p2.style.display=&#39;none&#39;;},700);   
  }
 }
</script>
</head>
<body>
<p id="p1"></p>
<p id="p2"></p>
 
</body>
</html>
Copy after login

The above is what I compiled for everyone. I hope it will be useful to you in the future. Everyone is helpful.

Related articles:

Detailed interpretation of Angular’s ​​error 404 issues

How to use the slider component in the WeChat applet

How to remember passwords on cookies in vue

The above is the detailed content of How to implement delay hiding function through JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!