1

这是我的代码:

    <HTML><head>
<Script language="JavaScript">
<!--
function changePos() 
{
 width = document.body.clientWidth;   //the width of the current document
 height = document.body.clientHeight; //the height of the current document
 Hoffset = img.offsetHeight;
 Woffset = img.offsetWidth;
 img.style.left = xPos;  
 img.style.top = yPos;  

 if (yon) 
 {
  yPos = yPos + 1;
 } 
 else 
 { 
  yPos = yPos - 1;
 }
 if(yPos < 0) 
 {
  yon = 1; yPos = 0;
 }
 if(yPos >= (height - Hoffset)) 
 {
  yon = 0; yPos = (height - Hoffset);
 }
}
//-->
</Script>
</head>
<body>
<IMG id="img" style="POSITION: absolute" src="Images\Colored.jpg">
<SCRIPT language=JavaScript>
<!-- 
 var height = 0;
 var Hoffset = 0;
 var Woffset = 0;
 var yon = 0;  //false
 var xPos = 20;
 var yPos = document.body.clientHeight;
 var Timer1 = setInterval('changePos()',30);
//-->
</Script>
</BODY>
</HTML>

我想让图像上下滚动,但不要停在页面边框上,换句话说,只要图像到达任一位置,我就需要图像在页面下方和页面上方!!!!

4

1 回答 1

0

改变

if(yPos < 0) 
 {
  yon = 1; yPos = 0;
 }
 if(yPos >= (height - Hoffset)) 
 {
  yon = 0; yPos = (height - Hoffset);
 }

if(yPos < -Hoffset) 
 {
  yon = 1; yPos = -Hoffset;
 }
 if(yPos >= height) 
 {
  yon = 0; yPos = height;
 }
于 2012-10-03T23:54:50.243 回答