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

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

 更新時(shí)間:2014年02月19日 14:42:30   作者:  
這篇文章主要介紹了javascript實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄代碼,需要的朋友可以參考下

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

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

復(fù)制代碼 代碼如下:

<body>
<div id="div1">
<span>側(cè)邊欄</span>
</div>
</body>

然后是css的樣式:

復(fù)制代碼 代碼如下:

#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è)邊欄是隱藏起來的如圖:

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

下面是完整代碼:

復(fù)制代碼 代碼如下:

<!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>無標(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>

相關(guān)文章

最新評(píng)論

民乐县| 汾西县| 岳西县| 茂名市| 周宁县| 开鲁县| 普宁市| 扎鲁特旗| 桐柏县| 衡阳县| 建昌县| 林周县| 开原市| 噶尔县| 潢川县| 寿光市| 武山县| 固镇县| 中山市| 罗田县| 桐庐县| 阜城县| 阿勒泰市| 汉阴县| 汉寿县| 包头市| 华宁县| 柯坪县| 宜君县| 阿坝县| 玛曲县| 东方市| 光山县| 天峻县| 台江县| 万安县| 根河市| 台前县| 凉山| 榆树市| 鹰潭市|