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

首頁 > 語言 > JavaScript > 正文

javascript實現(xiàn)動態(tài)側(cè)邊欄代碼

2024-05-06 16:01:15
字體:
供稿:網(wǎng)友
這篇文章主要介紹了javascript實現(xiàn)動態(tài)側(cè)邊欄代碼,需要的朋友可以參考下

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

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

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


<body>
<div>
<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;}

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

javascript實現(xiàn)動態(tài)側(cè)邊欄代碼

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

javascript實現(xiàn)動態(tài)側(cè)邊欄代碼

下面是完整代碼:

復(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>無標題文檔</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);//第一個參數(shù)為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>
<span>側(cè)邊欄</span>
</div>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 沙湾县| 锦屏县| 田林县| 原平市| 绿春县| 翼城县| 富顺县| 宿松县| 商河县| 佛坪县| 叶城县| 湄潭县| 徐汇区| 象州县| 余庆县| 衡山县| 龙岩市| 安吉县| 古蔺县| 瑞安市| 隆回县| 新兴县| 恭城| 昌邑市| 莲花县| 彝良县| 武强县| 桐城市| 张家港市| 陇西县| 河间市| 乌鲁木齐县| 华池县| 栾川县| 金湖县| 锦屏县| 禄丰县| 武冈市| 开化县| 新余市| 寿光市|