啊啊啊啊123
2016-07-14 13:54
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>运动</title>
<style type="text/css">
*{margin: 0;padding: 0;}
#box{width: 200px;height: 200px;background-color: red;position: relative;left: -200px;top: 0;}
#box span{width: 20px;height: 50px;position: absolute;top: 50px;left: 200px;background-color: blue;}
</style>
<script type="text/javascript">
window.onload=function(){
var obox = document.getElementById('box');
obox.onmouseover = function () {
startmove();
}
/* obox.onmouseout = function(){
backmove();
}
*/ }
var timer = null;
function startmove() {
clearIntelval(timer);
var obox = document.getElementById('box');
timer = setInterval(function () {
if (obox.offsetLeft==0) {
clearInterval(timer);
}else{
obox.style.left = obox.offsetLeft + 1 +"px";
}
},30)
}
/* function backmove(){
clearIntelval(timer);
var obox = document.getElementById('box');
timer = setInterval(function(){
if (obox.offsetLeft == -200) {
clearInterval(timer);
}else{
obox.style.left = obox.offsetLeft - 10 +"px";
}
},30)
}
*/
</script>
</head>
<body>
<div id="box"><span>分享</span></div>
</body>
</html>
如果你是用Sublime编辑器的话按照下面步骤装就好,记得装Node.js哦:
http://www.wiibil.com/website/sublimelinter-jshint-csslint.html
http://www.cnblogs.com/lhb25/archive/2013/05/02/sublimelinter-for-js-css-coding.html
建议装个语法检查插件,sublime可以用Linter 和Linter-js
clearIntelval这也是醉了
JS动画效果
113925 学习 · 1443 问题
相似问题
回答 3
回答 1