为什么动不了啊

来源:2-1 JS速度动画

DDjx

2015-12-07 19:53

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxx</title>
<style type="text/css">
body{
	margin:0;padding: 0;
}
#dds{
	width: 400px;
	height: 400px;
	position: relative;
	background-color: yellow;
	left: -400px;
}
#dd{
	background-color: blue;
	height: 50px;
	width: 50px;
	position: absolute;
	left: 400px;
	top: 175px;
}
</style>
<script type="text/javascript">
	window.onload=function () {
		var odiv=document.getElementById('dds');
		odiv.ommouseover = function(){
			startMove(400);
		}
		odiv.ommouseout = function(){
			startMove(0);
		}
	}
	var timer = null;
	function startMove(itarget){
		clearInterval(timer);
		var odiv = document.getElementById('dds');
		timer = setInterval(function(){
			var speed=0;
			if (odiv.offsetLeft>itarget) {
					speed=-10;
				}
			else{
					speed=10;
				}
			if (odiv.offsetLeft==itarget) {
				clearInterval(timer);
			}
			else{
				odiv.style.left=odiv.offsetLeft+speed+'px';
			}
		},30)
	}
</script>

</head>
<body>
	<div id='dds'>
		<span id='dd'>分享</span>
	</div>
</body>
</html>


写回答 关注

2回答

  • 木子舟义
    2015-12-07 19:57:43
    已采纳

    你的onmouseover 和 onmouseout 写错啦

    木子舟义 回复DDjx

    哈哈哈哈 加油~

    2015-12-07 20:19:26

    共 2 条回复 >

  • echo_kinchao
    2015-12-07 22:09:20

    你的onmouse写错了

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113920 学习 · 1502 问题

查看课程

相似问题