国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript 實現動態側邊欄實例詳解

2019-11-19 18:58:53
字體:
來源:轉載
供稿:網友

javascript 實現動態側邊欄

總的來說就是利用 鼠標懸停onmouseover   和  鼠標移除onmouseout 這兩個時間來完成的。

首先是HTML 結構

<body><div id="div1"><span>側邊欄</span></div></body>

然后是css的樣式:

#div1{  width:150px;  height:200px;  background:#999999;  position:absolute;  left:-150px;}span{  width:20px;  height:70px;  line-height:23px;  background:#09C;  position:absolute;  right:-20px;  top:70px;}

默認的樣式 側邊欄是隱藏起來的如圖:

 

當鼠標移入以后如圖:

 下面是完整代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><style type="text/css">#div1{  width:150px;  height:200px;  background:#999999;  position:absolute;  left:-150px;}span{  width:20px;  height:70px;  line-height:23px;  background:#09C;  position:absolute;  right:-20px;  top:70px;}</style><script>window.onload=function(){  var odiv=document.getElementById('div1');  odiv.onmouseover=function ()  {        startmove(0,10);//第一個參數為div  left屬性的目標值  第二個為 每次移動多少像素        } odiv.onmouseout=function () {   startmove(-150,-10);   }  }    var timer=null;function startmove(target,speed){     var odiv=document.getElementById('div1');clearInterval(timer);   timer=setInterval(function (){        if(odiv.offsetLeft==target)    {      clearInterval(timer);      }      else      {      odiv.style.left=odiv.offsetLeft+speed+'px';      }        },30)    }  </script></head><body><div id="div1"><span>側邊欄</span></div></body></html>

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桂东县| 大关县| 新晃| 长兴县| 延吉市| 蕲春县| 茂名市| 房山区| 都安| 宜宾市| 永福县| 兴化市| 新干县| 谢通门县| 高阳县| 张掖市| 辰溪县| 巫溪县| 成都市| 龙游县| 保德县| 育儿| 合作市| 札达县| 高要市| 万山特区| 淮滨县| 绩溪县| 高陵县| 榆林市| 蕉岭县| 罗城| 霍州市| 通河县| 资溪县| 枞阳县| 碌曲县| 忻州市| 汝城县| 屏山县| 玛沁县|