首頁  >  文章  >  web前端  >  透過JS如何實現延遲隱藏功能

透過JS如何實現延遲隱藏功能

亚连
亚连原創
2018-06-14 16:42:311612瀏覽

下面我就為大家分享一篇JS實作延遲隱藏功能的方法(類似QQ頭像滑鼠放上展示資訊),具有很好的參考價值,希望對大家有幫助。

JS實作延遲隱藏

<!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>

上面是我整理給大家的,希望今後會對大家有幫助。

相關文章:

詳細解讀Angular有關報錯404問題

在微信小程式中如何使用slider元件

#在vue中如何實作記住密碼到cookie上

以上是透過JS如何實現延遲隱藏功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn