javascript图片飘动效果

本文介绍了一个简单的网页动画实现方法,通过JavaScript控制图片在页面中模拟荡秋千的效果。图片会上下移动,实现类似荡秋千的动作,提供了一段具体的代码实现。
 <html>
<head>
<title>会荡秋千的图片</title>
<body>
<table border=0 width=100% height=181>
<tr>
  <td width=100% height=19>
   <p align=center>
   <span style="background-color:#ccffcc;font-size:10pt">会荡秋千的图片</span></td>
</tr>
<tr>
<td width=100% style="border:1 ridge:#00ffff"height=17>
<p align=center>
<span style="font-size:9pt">一个图片上下移动,像荡秋千一样!</span></p>
</td>
</tr>
<tr>
<td width=100% style="border:1 ridge:#00ffff" height=133 valign=bottom>
<img border=0 id="picture" name="" src="2.png" style="position:absolute;left:200;top:90" width=48 height=93>
</td>
</tr>
</table>
<script language="javascript">
var step=0;
var currentY;
var beMoveObj=new Image();
var window_height=document.body.offsetHeight;
beMoveObj=document.images["picture"];
var image_height=beMoveObj.height;
var top=Math.round((window_height+500)/2);
var bottom=Math.round((window_height-500)/2)-image_height;
var currentY=top;
var direction=1;
 function startmove()
{
 beMoveObj.style.top=currentY;
 currentY-=step*direction;
 if(currentY>=(top+bottom)/2){
   if(direction==1) step++;
   else step--;
  }
 else{
   if(direction==1) step--;
   else step++;
   }
 if(currentY<=bottom){
   currentY=bottom;
   direction=-1;}
 if(currentY>=top){
  currentY=top;
  direction=1;
}
setTimeout('startmove()',60);
}

startmove();
</script>
</body>
</html>



    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值