JavaScript实现分享侧边栏

1.HTML结构:

<div id="div1">

<span>分享到</span>

</div>

2.css样式结构:

#div1{
				width:150px;height:200px;background-color:#7FFFD4;position:absolute;
			left:-150px;}
			#div1 span{position:absolute;width:20px;height:60px;line-height:20px;background-color:#0000FF;
			right:-20px;top:70px;
			}

3.JavaScript:

 1 window.onload=function(){
 2                 var odiv=document.getElementById('div1');
 3                 odiv.onmousemove=function(){
 4                     startmover(10,0);
 5                 }
 6                 odiv.onmouseout=function(){
 7                     startmover(-10,-150);
 8                 }
 9             }
10             var timer=null;
11             
12             function startmover(speed,itarget){
13                 var odiv=document.getElementById('div1');
14                 clearInterval(timer);
15                 timer=setInterval(function(){
16                     
17                     if(odiv.offsetLeft==itarget){
18                         clearInterval(timer);
19                     }else{
20                         odiv.style.left=odiv.offsetLeft+speed+'px';
21                     }
22                 },30)
23             }

 

posted on 2017-08-04 10:45  封寻丸子  阅读(206)  评论(0编辑  收藏  举报

导航