HTML+CSS+JS实现速度动画
2017-11-04 14:33
579 查看
1.box.html代码:
2.box.css代码:
3.box.js代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>广告</title> <link rel="stylesheet" type="text/css" href="box.css"/> <script src="box.js"></script> </head> <body> <div id="box"> <span id="smallbox"></span> </div> </body> </html>
2.box.css代码:
body { padding: 0px; margin: 0px; } #box { height: 200px; width: 200px; background-color: rebeccapurple; position: relative; -webkit-border-radius: 5%; -moz-border-radius: 5%; border-radius: 5%; left: -200px; } #smallbox { height: 50px; width: 20px; position: absolute; background-color: dodgerblue; -webkit-border-radius: 5%; -moz-border-radius: 5%; border-radius: 5%; left: 200px; top: 75px; }
3.box.js代码:
window.onload = function () { var box = document.getElementById('box'); box.onmouseover = function () { move(10, 0); } box.onmouseout = function () { move(-10, -200); } }; var timer = null; function move(speed, destination) { clearInterval(timer); var box = document.getElementById('box'); timer = setInterval(function () { if (box.offsetLeft == destination) { clearInterval(timer); } else { box.style.left = box.offsetLeft + speed + 'px'; } }, 30); }
相关文章推荐
- HTML+CSS+JS实现透明度动画
- HTML+CSS+JS实现缓冲动画
- 原生JS实现CSS动画效果
- 使用Animate.css和wow.js,实现各大网站常用的页面加载动画
- HTML,CSS,JS实现网页聊天窗口
- Html与Js连用实现动画
- .NET, MVC框架下利用html, CSS,js实现弹出窗口
- html,css,js实现老虎机游戏以及出现的问题
- 用 js、html、css实现一个弹出提示控件:
- html+css+js实现原生轮播特效
- html css js 实现Tab标签页示例代码
- HTML+CSS+JS实现轮播效果
- html+css+js实现类淘宝星级宝贝评价系统
- html和css动画(恒定速度)
- UL LI结构实现二级导航菜单(HTML+CSS+JS)
- HTML中用CSS实现图片与内容前后翻转动画效果
- js+html+css实现简单页面交互功能(2015知乎前端笔试题)http://v.youku.com/v_show/id_XMTI0ODQ5NTAyOA==.html?from=y1.7-1.2
- js实现单一html页面两套css切换代码
- 用html+css+js实现选项卡切换效果
- 通过JS控制CSS实现连帧动画