问答详情
源自:2-1 JS速度动画

为什么动不了啊

<!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>


提问者:DDjx 2015-12-07 19:53

个回答

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

    你的onmouseover 和 onmouseout 写错啦

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

    你的onmouse写错了