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

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 21:04:58
字體:
供稿:網(wǎng)友

總的來說就是利用 鼠標(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>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁乡县| 宜川县| 新竹县| 娱乐| 临清市| 郓城县| 江陵县| 布尔津县| 古浪县| 简阳市| 姜堰市| 瑞昌市| 辽宁省| 曲麻莱县| 开江县| 蛟河市| 土默特左旗| 望谟县| 张北县| 新营市| 邛崃市| 集安市| 南宁市| 辽中县| 莲花县| 铜鼓县| 东方市| 贵德县| 新源县| 怀化市| 高陵县| 翁牛特旗| 团风县| 甘南县| 崇文区| 台南县| 昌图县| 泰来县| 五大连池市| 淮安市| 梁山县|