JS運(yùn)動(dòng)框架之分享側(cè)邊欄動(dòng)畫(huà)實(shí)例
本文實(shí)例講述了JS運(yùn)動(dòng)框架之分享側(cè)邊欄動(dòng)畫(huà)實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
#div1{
width:319px;
height: 340px;
border: 1px solid #FFF;
position: absolute;
top:100px;
left:-320px;
background-image: url(images/1.png);
background-repeat:no-repeat ;
}
#div1 span{
width:30px;
height: 130px;
border: 1px solid blue;
position: absolute;
right:-23px;
top:95px;
background: red;
font-family: "微軟雅黑";
color: #FFFFFF;
text-align: center;
line-height: 40px;
border-radius: 0px 200px 200px 0px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div1");
var oSpan=oDiv.getElementsByTagName('span')[0];
var time=null;
var speed=8;
oDiv.onmouseover=function(){//這里給整個(gè)div加鼠標(biāo)移入的事件
clearInterval(time);
time=setInterval(function(){
if(oDiv.offsetLeft>=0){clearInterval(time);}
else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},1);
}
oDiv.onmouseout=function(){//這里給整個(gè)div加鼠標(biāo)移出事件
clearInterval(time);
time=setInterval(function(){
if(oDiv.offsetLeft<=-320){clearInterval(time);}
else{
oDiv.style.left=oDiv.offsetLeft-speed+'px';
}
},1);
}
}
</script>
</head>
<body>
<div id="div1">
<span>分享到</span>
</div>
</body>
</html>
優(yōu)化后的代碼:
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
#div1{
width:319px;
height: 340px;
border: 1px solid #FFF;
position: absolute;
top:100px;
left:-320px;
background-image: url(images/1.png);
background-repeat:no-repeat ;
}
#div1 span{
width:30px;
height: 130px;
border: 1px solid blue;
position: absolute;
right:-23px;
top:95px;
background: red;
font-family: "微軟雅黑";
color: #FFFFFF;
text-align: center;
line-height: 40px;
border-radius: 0px 200px 200px 0px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div1");
var oSpan=oDiv.getElementsByTagName('span')[0];
var time=null;
var spe=8;
var speed=null;
function move(bord){
clearInterval(time);
time=setInterval(function(){
if(oDiv.offsetLeft>bord){speed=-spe;}
else{speed=spe;}
if(oDiv.offsetLeft==bord){clearInterval(time);}
else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},1);
}
oDiv.onmouseover=function(){//這里給整個(gè)div加鼠標(biāo)移入的事件
move(0);
}
oDiv.onmouseout=function(){//這里給整個(gè)div加鼠標(biāo)移出事件
move(-320);
}
}
</script>
</head>
<body>
<div id="div1">
<span>分享到</span>
</div>
</body>
</html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
- 博客側(cè)邊欄模塊跟隨滾動(dòng)條滑動(dòng)固定效果的實(shí)現(xiàn)方法(js+jquery等)
- javascript實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄代碼
- JavaScript實(shí)現(xiàn)簡(jiǎn)單的隱藏式側(cè)邊欄功能示例
- javascript 實(shí)現(xiàn)動(dòng)態(tài)側(cè)邊欄實(shí)例詳解
- 利用js編寫(xiě)響應(yīng)式側(cè)邊欄
- JS實(shí)現(xiàn)側(cè)邊欄鼠標(biāo)經(jīng)過(guò)彈出框+緩沖效果
- 基于slideout.js實(shí)現(xiàn)移動(dòng)端側(cè)邊欄滑動(dòng)特效
- JavaScript中實(shí)現(xiàn)無(wú)縫滾動(dòng)、分享到側(cè)邊欄實(shí)例代碼
- JS實(shí)現(xiàn)京東商品分類側(cè)邊欄
- js實(shí)現(xiàn)淘寶固定側(cè)邊欄
相關(guān)文章
js通過(guò)Date對(duì)象實(shí)現(xiàn)倒計(jì)時(shí)動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了js通過(guò)Date對(duì)象實(shí)現(xiàn)倒計(jì)時(shí)動(dòng)畫(huà)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
前端實(shí)現(xiàn)添加水印功能的常見(jiàn)方式小結(jié)
前端水印就是在網(wǎng)頁(yè)或應(yīng)用程序的前端界面上添加的一種標(biāo)記,通常是文本、圖標(biāo)或圖案等形式,下面小編就來(lái)和大家介紹四個(gè)常用的方法吧2025-03-03
JS 簡(jiǎn)單展開(kāi)關(guān)閉切換代碼
一個(gè)JS實(shí)現(xiàn)的展開(kāi)關(guān)閉來(lái)回切換的代碼。用于一段內(nèi)容的顯示與隱藏,點(diǎn)一次隱藏,再點(diǎn)一次就顯示,來(lái)回切換。2010-04-04
js隱藏與顯示回到頂部按鈕及window.onscroll事件應(yīng)用
現(xiàn)在大多數(shù)網(wǎng)站都會(huì)添加這種功能:當(dāng)滾動(dòng)條滾動(dòng)到頁(yè)面的下方時(shí),頁(yè)面的右下角會(huì)顯示出來(lái)一個(gè)“回到頂部”的按鈕或連接;那么,如何控制“回到頂部”按鈕的顯示或隱藏呢;本文介紹詳細(xì)實(shí)現(xiàn)方法,感興趣的你可不要走開(kāi)哦2013-01-01
IE6 彈出Iframe層中的文本框“經(jīng)?!睙o(wú)法獲得輸入焦點(diǎn)
IE6間歇性精神障礙 彈出Iframe層中的文本框“經(jīng)?!睙o(wú)法獲得輸入焦點(diǎn)的解決方法。2009-12-12
JavaScript使用addEventListener添加事件監(jiān)聽(tīng)用法實(shí)例
這篇文章主要介紹了JavaScript使用addEventListener添加事件監(jiān)聽(tīng)的方法,實(shí)例分析了addEventListener方法的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06

