JS運動框架之分享側邊欄動畫實例
來源:易賢網(wǎng) 閱讀:757 次 日期:2015-03-06 10:53:39
溫馨提示:易賢網(wǎng)小編為您整理了“JS運動框架之分享側邊欄動畫實例”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了JS運動框架之分享側邊欄動畫,實例分析了javascript操作div及css的技巧,需要的朋友可以參考下

本文實例講述了JS運動框架之分享側邊欄動畫實現(xiàn)方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

代碼如下:

<!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加鼠標移入的事件

clearInterval(time);

time=setInterval(function(){

if(oDiv.offsetLeft>=0){clearInterval(time);}

else{

oDiv.style.left=oDiv.offsetLeft+speed+'px';

}

},1);

}

oDiv.onmouseout=function(){//這里給整個div加鼠標移出事件

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)化后的代碼:

代碼如下:

<!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加鼠標移入的事件

move(0);

}

oDiv.onmouseout=function(){//這里給整個div加鼠標移出事件

move(-320);

}

}

</script>

</head>

<body>

<div id="div1">

<span>分享到</span>

</div>

</body>

</html>

希望本文所述對大家的javascript程序設計有所幫助。

更多信息請查看IT技術專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機網(wǎng)站地址:JS運動框架之分享側邊欄動畫實例

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)