function rgb_color(){//随机rgb色生成函数,返回值为rgb颜色字符串 var r=parseInt(Math.random()*255); var g=parseInt(Math.random()*255); var b=parseInt(Math.random()*255); var newcolor="rgb("+r+","+g+","+b+")"; return newcolor; } function rgba_color(){//随机rgba色生成函数,返回值为rgba颜色字符串 var r=parseInt(Math.random()*255); var g=parseInt(Math.random()*255); var b=parseInt(Math.random()*255); var a=Math.random(); var newcolor="rgba("+r+","+g+","+b+","+a+")"; return newcolor; } function getbyclass(parent,classname){//通过类名获取元素函数,参数为父元素、类名,返回值为元素数组 var result=new Array(); var allclass=parent.getElementsByTagName('*'); for (var i=0; i1000)//由于小数的特殊性,无法保证两数一致,相差很小时忽略差距 { obj.speed[attr][j]=(temp-cur[j])/5; obj.speed[attr][j]=obj.speed[attr][j]>0?Math.ceil(obj.speed[attr][j]):Math.floor(obj.speed[attr][j]); next[j]=(cur[j]+obj.speed[attr][j])/10000; //console.log(j+" "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//运动过程中的参数值 } else{ next[j]=parseInt(oTarget[attr][j]*10000)/10000;//已经到达目标的值保持 count++;//记录以达到目标的个数 //console.log(attr+"count"+count); } } } else{ for (var j=0;j0?Math.ceil(obj.speed[attr][j]):Math.floor(obj.speed[attr][j]); next[j]=cur[j]+obj.speed[attr][j]; //console.log(j+" "+attr+" "+cur[j]+' '+obj.speed[attr][j]+' '+next[j]+' '+oTarget[attr][j]) ;//运动过程中的参数值 } else{ next[j]=oTarget[attr][j];//已经到达目标的值保持 count++;//记录以达到目标的个数 //console.log(attr+"count"+count); } } } css(obj,attr,next); } var allattr=0;//所有属性计数器清零 for(attr in oTarget) { for (var i=0;i=(win('height')-obj.offsetHeight))//碰撞到底部,y轴速度反向,x轴速度减小 { speedY*=-0.8; speedX*=0.8; top=(win('height')-obj.offsetHeight); }else if (top<=0)//碰撞到顶部,y轴速度反向,x轴速度减小 { speedY*=-0.8; speedX*=0.8; top=0; } if (left>=(win('width')-obj.offsetWidth))//碰撞到右侧,X轴速度反向且减小 { speedX*=-0.8; left=(win('width')-obj.offsetWidth); }else if (left<=0)//碰撞到左侧,X轴速度反向且减小 { speedX*=-0.8; left=0; } if (Math.abs(speedX)<1)//速度很小时视为停止 { speedX=0; } if (Math.abs(speedY)<1)//速度很小时视为停止 { speedY=0; } if(speedX==0&&speedY==0&&top==(win('height')-obj.offsetHeight)){//运动过程停止 clearInterval(timer); } obj.style.left=left+'px';//应用定位 obj.style.top=top+'px'; },30); } function drag(obj){//实现拖拽,参数为对象 obj.onmousedown=function (ev){//按下鼠标 var oev=ev||event; var disX=oev.clientX-obj.offsetLeft; var disY=oev.clientY-obj.offsetTop; document.onmousemove=function (ev){//拖动鼠标 var oev=ev||event; var left=oev.clientX-disX; var top=oev.clientY-disY; obj.style.left=left+'px';//更新对象的位置 obj.style.top=top+'px'; } document.onmouseup=function (){//抬起鼠标 document.onmousemove=null; document.onmouseup=null; } } } /**************************************************运动框架结束*****************************************************/