最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
js实现4个方向滚动的球
时间:2017-05-28 编辑:简简单单 来源:一聚教程网
效果图:
代码如下:
代码如下 | 复制代码 |
*{ margin: 0; padding: 0; } #wrap{ width: 800px; height: 500px; border: 1px solid deeppink; margin-left: 10px; margin-top: 5px; float: left; } #input1{ width: 80px; margin: 5px auto 5px 10px; font-size: 0; float: left; } #div1{ width: 100px; height: 100px; background: hotpink; position: absolute; top: 20px; left: 30px; border-radius: 100px; box-shadow: 0px 5px 5px rgba(0,0,0,.5); } input{ width: 100px; height: 40px; line-height: 40px; text-align: center; font-size: 18px; display: block; background: palegreen; margin-bottom: 5px; }
var oBtn=document.getElementById('btn1'); var oDiv=document.getElementById('div1'); var oBtn2=document.getElementById('btn2'); var oBtn3=document.getElementById('btn3'); var oBtn4=document.getElementById('btn4'); oBtn4.onclick=function(){ move(oDiv,10,380,'0px 5px 5px rgba(0,0,0,.5)','top'); } oBtn3.onclick=function(){ move(oDiv,-10,30,'0px -5px 5px rgba(0,0,0,.5)','top'); } oBtn2.onclick=function(){ move(oDiv,-10,40,'-5px 5px 5px rgba(0,0,0,.5)','left'); } oBtn.onclick=function(){ move(oDiv,10,680,'5px 5px 5px rgba(0,0,0,.5)','left'); } function move(obj,val,target,bs,dir){ obj.style.boxShadow=bs; clearInterval(obj.timer); obj.timer=setInterval(function(){ var speed=parseInt(getStyle(obj,dir))+val; if(speed>=target&&val>0){ speed=target; } if(speed<=target&&val<0){ speed=target } obj.style[dir]=speed+'px'; if(speed==target){ clearInterval(obj.timer); } },30); } function getStyle(obj,sty){ return obj.currentStyle?obj.currentStyle[sty]:getComputedStyle(obj)[sty]; }
|
-
上一个: Bootstrap输入框组件简单实现代码
相关文章
- js实现彩色条纹滚动条效果 06-29
- js实现无缝滚动图 04-24
- JS实现的DIV块来回滚动效果示例 03-17
- js实现文本上下来回滚动的教程 03-13
- 原生js实现中奖信息无间隙滚动效果 02-06
- js实现消息滚动效果的教程 02-06