js原生运动



	
   
   
	Document


wheel!

<script> function addLoadEvent(func){ var oldοnlοad=window.onload; //将现有的事件处理函数的值存入变量中 if(typeof window.onload!="function"){ window.οnlοad=func; //如果这个事件处理函数没有绑定任何函数,就把新函数添加给它 }else{ window.οnlοad=function(){ oldonload(); func(); //如果已经绑定了函数,就把新函数追加到现有指令的末尾 } } } //onload事件会在页面或则图片加载完成时执行,window.onload = function(){} 它只能绑定一个函数如果我们 //需要绑定多个函数就要用到我们可以用addLoadEvent函数 //以后不管有多少函数我们都可以这样执行: //addLoadEvent(firstfunction); //addLoadEvent(secondfunction); //addLoadEvent(thirdfunction); function moveMessage(){ if(!document.getElementById) return false; //如果不能获取DOM元素就返回false if(!document.getElementById("message")) return false; var elem=document.getElementById("message"); var ypos=parseInt(elem.offsetTop); var xpos=parseInt(elem.offsetLeft); console.log(ypos) console.log(xpos) var num = 0; if(xpos==200&&ypos==100){ return true; clearInterval(timer); } if(xpos<200){ xpos++; num++; console.log(num); } if(xpos>200){ xpos--; } if(ypos<100){ ypos++; } if(ypos>100){ ypos--; } elem.style.left=xpos+"px"; elem.style.top=ypos+"px"; timer=setTimeout("moveMessage()",10); } addLoadEvent(moveMessage); </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值