求大神幫忙看看為什么沒有移動進(jìn)去?
<!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">
<style type="text/css">
body{margin:0px;
padding:0px;}
#div1{
?? ?width:200px;
?? ?height:300px;
?? ?background-color:red;
?? ?position:relative;
?? ?left:-200px;
?? ?top:75px;}
?? ?#div1 span{
?? ??? ?background-color:blue;
?? ??? ?position:absolute;
?? ??? ?left:200px;
?? ??? ?top:175px;}
</style>
<script>
?? ?window.onload=function(){
?? ??? ?var ddiv=document.getElementById("div1");
?? ??? ?ddiv.onmouseover=function(){
?? ??? ??? ?startMove();}
?? ??? ?}
?? ??? ?var timer=null;
?? ??? ?function startMove(){
?? ??? ??? ?clearInterval(timer);
?? ??? ??? ?var ddiv=document.getElementById("div1");
?? ??? ??? ?timer=setInterval(function(){
?? ??? ??? ??? ?if(ddiv.offsetLeft==0){
?? ??? ??? ??? ??? ?clearInterval(timer);}
?? ??? ??? ??? ??? ?else{
?? ??? ??? ??? ?ddiv.style.left=ddiv.offsetLeft+10+"px";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?},30);
?? ??? ?}
?? ?ddiv.onmouseout=function(){
?? ??? ?startMove1();}
?? ??? ?function startMove1(){
?? ??? ??? ?clearInterval(timer);
?? ??? ??? ?var ddiv=document.getElementById("div1");
?? ??? ??? ?timer=setInterval(function(){
?? ??? ??? ??? ?if(ddiv.offsetLeft==-200){
?? ??? ??? ??? ??? ?clearInterval(timer);}
?? ??? ??? ??? ??? ?else{
?? ??? ??? ??? ?ddiv.style.left=ddiv.offsetLeft-10+"px";
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?},30);
?? ??? ?}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
</head>
<body>
<div id='div1'><span id='share'>分享</span></div>
</body>
</html>
2016-04-15
我的計時器觸發(fā)沒有放到window.onload里面去。
2016-04-15
已經(jīng)發(fā)現(xiàn)問題