JS運動框架之分享側(cè)邊欄動畫實例
更新時間:2015年03月03日 11:03:33 作者:mikyou
這篇文章主要介紹了JS運動框架之分享側(cè)邊欄動畫,實例分析了javascript操作div及css的技巧,需要的朋友可以參考下
本文實例講述了JS運動框架之分享側(cè)邊欄動畫實現(xiàn)方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<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(){//這里給整個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(){//這里給整個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>
<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(){//這里給整個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(){//這里給整個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)化后的代碼:
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<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(){//這里給整個div加鼠標(biāo)移入的事件
move(0);
}
oDiv.onmouseout=function(){//這里給整個div加鼠標(biāo)移出事件
move(-320);
}
}
</script>
</head>
<body>
<div id="div1">
<span>分享到</span>
</div>
</body>
</html>
<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(){//這里給整個div加鼠標(biāo)移入的事件
move(0);
}
oDiv.onmouseout=function(){//這里給整個div加鼠標(biāo)移出事件
move(-320);
}
}
</script>
</head>
<body>
<div id="div1">
<span>分享到</span>
</div>
</body>
</html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
您可能感興趣的文章:
- 博客側(cè)邊欄模塊跟隨滾動條滑動固定效果的實現(xiàn)方法(js+jquery等)
- javascript實現(xiàn)動態(tài)側(cè)邊欄代碼
- JavaScript實現(xiàn)簡單的隱藏式側(cè)邊欄功能示例
- javascript 實現(xiàn)動態(tài)側(cè)邊欄實例詳解
- 利用js編寫響應(yīng)式側(cè)邊欄
- JS實現(xiàn)側(cè)邊欄鼠標(biāo)經(jīng)過彈出框+緩沖效果
- 基于slideout.js實現(xiàn)移動端側(cè)邊欄滑動特效
- JavaScript中實現(xiàn)無縫滾動、分享到側(cè)邊欄實例代碼
- JS實現(xiàn)京東商品分類側(cè)邊欄
- js實現(xiàn)淘寶固定側(cè)邊欄
相關(guān)文章
《JavaScript高級程序設(shè)計》閱讀筆記(三) ECMAScript中的引用類型
ECMAScript中的引用類型,主要包括Object類、Boolean類、Number類、String類、instanceof運算符2012-02-02詳解webpack 打包文件體積過大解決方案(code splitting)
這篇文章主要介紹了webpack 打包文件體積過大解決方案(code splitting),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04基于javascript實現(xiàn)按圓形排列DIV元素(二)
本篇文章主要介紹基于javascript實現(xiàn)按圓形排列DIV元素的方法,此文著重于介紹怎樣實現(xiàn)的按圓形排列DIV元素的運動原理和實現(xiàn)效果代碼,需要的朋友來看下吧2016-12-12詳解JavaScript如何實現(xiàn)異步并發(fā)任務(wù)控制器
實現(xiàn)一個控制并發(fā)數(shù)的任務(wù)隊列?、實現(xiàn)一個異步并發(fā)任務(wù)控制器,這已經(jīng)是非常經(jīng)典的手寫題目了,因為其中涉及?異步?和?并發(fā)?的內(nèi)容,所以本文就來講講到底如何實現(xiàn)呢2023-05-05JS面向?qū)ο蠡A(chǔ)講解(工廠模式、構(gòu)造函數(shù)模式、原型模式、混合模式、動態(tài)原型模式)
這篇文章主要介紹了面向?qū)ο驤S基礎(chǔ)講解,工廠模式、構(gòu)造函數(shù)模式、原型模式、混合模式、動態(tài)原型模式,需要的朋友可以參考下2014-08-08