宝哥软件园

javascript多物体运动实现方法分析

编辑:宝哥软件园 来源:互联网 时间:2021-09-18

本文实例讲述了爪哇岛描述语言多物体运动实现方法。分享给大家供大家参考,具体如下:

这里需要注意:每个运动物体的定时器作为物体的属性独立出来互不影响,属性与运动对象绑定,不能公用。

运行效果截图如下:

例子:

!doctype html html ownerta charset=' utf-8 '标题多物体运动/title style div { width :100 px;高度:100 px背景:红色;float : leftmargin :10 pxborder :1 px纯黑;opa city 33600.3 filter : alpha(不透明度=30);}/stylescriptwindow。onload=function(){ var ADiv=document。getelementsbytagname(' div ');aDiv[0].onmouseover=function(){ startMove(this,' width ',300);};aDiv[0].onmouseout=function(){ startMove(this,' width ',100);};aDiv[1].onmouseover=function(){ startMove(这个,‘高度’,300);};aDiv[1].onmouseout=function(){ start move(这个,‘高度’,100);};aDiv[2].onmouseover=function(){ startMove(此处为'不透明度',100);};aDiv[2].onmouseout=function(){ startMove(this,' opacity ',30);};aDiv[3].onmouseover=function(){ startMove(this,' borderWidth ',20);};aDiv[3].onmouseout=function(){ startMove(this,' borderWidth ',1);};};函数getStyle(obj,attr){ if(obj。currentstyle){ return obj。current style[attr];} else { return getComputedStyle(obj,false)[attr];} }函数startMove(obj,attr,iTarget){ clearInterval(obj。计时器);物体。timer=setInterval(function(){ var ICur=0;if(attr=='不透明度){ ICur=ParSeint(ParSefloat(GetStyle(obj,attr))* 100);} else { ICur=ParSeint(GetStyle(obj,attr));} var iSpeed=(itar get-ICur)/8;iSpeed=iSpeed 0?数学天花板:数学地板;if(ICur==itar get){ ClearInterval(obj。计时器);}else{ if(attr=='不透明度){ obj.style.filter='alpha(不透明度='(IcR isPeed)')';物体。风格。不透明度=(ICur IsPeed)/100;} else { obj。style[attr]=ICur isPeed ' px ';} } }, 30);}/脚本/标题dydiv/div/div/div/div/div/div/body/html更多关于Java脚本语言运动效果相关内容可查看本站专题: 《JavaScript运动效果与技巧汇总》

希望本文所述对大家Java脚本语言程序设计有所帮助。

更多资讯
游戏推荐
更多+