<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>
<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>
本文介绍了一个简单的网页动画实现方法,通过JavaScript控制图片在页面中模拟荡秋千的效果。图片会上下移动,实现类似荡秋千的动作,提供了一段具体的代码实现。
3717

被折叠的 条评论
为什么被折叠?



