最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript 實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄實(shí)例詳解

 更新時(shí)間:2016年11月11日 14:10:50   投稿:lqh  
這篇文章主要介紹了javascript 實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄實(shí)例詳解的相關(guān)資料,并附實(shí)例代碼,幫助大家學(xué)習(xí)理解,需要的朋友可以參考下

javascript 實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄

總的來(lái)說(shuō)就是利用 鼠標(biāo)懸停onmouseover   和  鼠標(biāo)移除onmouseout 這兩個(gè)時(shí)間來(lái)完成的。

首先是HTML 結(jié)構(gòu)

<body>
<div id="div1">
<span>側(cè)邊欄</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;}

默認(rèn)的樣式 側(cè)邊欄是隱藏起來(lái)的如圖:

 

當(dāng)鼠標(biāo)移入以后如圖:

 下面是完整代碼:


<!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>無(wú)標(biāo)題文檔</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);//第一個(gè)參數(shù)為div  left屬性的目標(biāo)值  第二個(gè)為 每次移動(dòng)多少像素
    
    }
 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>側(cè)邊欄</span>
</div>
</body>
</html>

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

相關(guān)文章

最新評(píng)論

双柏县| 南丹县| 玉龙| 邛崃市| 左云县| 柳江县| 祥云县| 漳州市| 福泉市| 延长县| 青龙| 隆化县| 樟树市| 恩平市| 麻江县| 榆中县| 洛阳市| 贵溪市| 福建省| 汉川市| 石台县| 孟村| 云南省| 竹山县| 辽阳县| 乌鲁木齐县| 莱芜市| 曲沃县| 卓尼县| 余庆县| 姜堰市| 南郑县| 南丰县| 图木舒克市| 麻栗坡县| 资兴市| 金寨县| 横山县| 固镇县| 景东| 深圳市|