麻煩看一下我哪里寫錯了...注釋掉的部分就是自己寫的運動<!DOCTYPE html><html lang="en"><head> ? ?<meta charset="UTF-8"> ? ?<title>Title</title> ? ?<style> div { ? ? ? ? ? ?width: 100px; height: 100px; background-color:pink; margin: 10px; float: left; border: 10px solid #000; font-size: 16px; } ? ?</style> ? ?<script src="move.js"></script> ? ?<script> window.onload=function() ? ? ? ?{ ? ? ? ? ? ?var div1=document.getElementById("div1"); var div2=document.getElementById("div2"); var div3=document.getElementById("div3"); div1.onmouseover=function () ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ?yundong(this,'height',500); } ? ? ? ? ? ?div1.onmouseout=function () ? ? ? ? ? ? ? ?{ ? ? ? ? ? ? ? ? ? ?yundong(this,'height',100); } ? ? ? ? ? ?div2.onmouseover=function () ? ? ? ? ? ?{ ? ? ? ? ? ? ? ?yundong(this,"width",500); } ? ? ? ? ? ?div2.onmouseout=function () ? ? ? ? ? ?{ ? ? ? ? ? ? ? ?yundong(this,"width",100); } ? ? ? ? ? ?div3.onmouseover=function () ? ? ? ? ? ?{ ? ? ? ? ? ? ? ?yundong(this,"fontSize",50); } ? ? ? ? ? ?div3.onmouseout=function () ? ? ? ? ? ?{ ? ? ? ? ? ? ? ?yundong(this,"fontSize",10); } ? ? ? ?}//// ? ? ? ?function getStyle(obj,name)// ? ? ? ?{// ? ? ? ? ? ?if(obj.currentStyle)// ? ? ? ? ? ?{// ? ? ? ? ? ? ? ?return obj.currentStyle[name]// ? ? ? ? ? ?}// ? ? ? ? ? ?else// ? ? ? ? ? ?{// ? ? ? ? ? ? ? ?return getComputedStyle(obj,false)[name];// ? ? ? ? ? ?}// ? ? ? ?}//// ? ? ? ?function yundong(obj,bb,mubiao)// ? ? ? ?{//// ? ? ? ? ? ?clearInterval(obj.timer);// ? ? ? ? ? ?obj.timer=setInterval(function()// ? ? ? ? ? ? ? ?{// ? ? ? ? ? ? ? ? ? ?var cur=parseInt(getStyle(obj,bb));// ? ? ? ? ? ? ? ? ? ?sudu=(mubiao-cur)/6;// ? ? ? ? ? ? ? ? ? ?sudu=sudu>0?Math.ceil(sudu):Math.floor(sudu);// ? ? ? ? ? ? ? ? ? ?if(cur==mubiao)// ? ? ? ? ? ? ? ? ? ?{// ? ? ? ? ? ? ? ? ? ? ? ?clearInterval(obj.timer)// ? ? ? ? ? ? ? ? ? ?}// ? ? ? ? ? ? ? ? ? ?else// ? ? ? ? ? ? ? ? ? ?{// ? ? ? ? ? ? ? ? ? ? ? ?obj.style[bb]=cur+sudu+"px";// ? ? ? ? ? ? ? ? ? ?}// ? ? ? ? ? ? ? ?},30)// ? ? ? ?} </script></head><body><div id="div1">變高</div><div id="div2">變寬</div><div id="div3">dasf</div></body></html>
自己寫了個js運動框架, 放在代碼里可以用,<script src="move.js"></script>這樣就沒效果..
楊念
2017-04-02 20:41:15