屏幕滚动
1、屏幕弹球
<div id="img" style="position:absolute;">
<img src="images/8b3d94e5-044e-497a-9767-6860edd759a9.gif" border="0">
</div>
<SCRIPT LANGUAGE="JavaScript">
<!--
var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function www_helpor_net() {
img.visibility = "visible";
interval = setInterval('changePos()', delay);
}
www_helpor_net();
-->
</script>
2、Marquee类似的但连续滚动
上下滚动
<div align="center" id="demo" style="overflow:hidden;height:125px;width:70px;">
<div id="demo1">
<!-- 定义内容-->
<img src="images/button.jpg" />
<img src="images/button.jpg" />
<img src="images/button.jpg" />
<img src="images/button.jpg" />
<img src="images/button.jpg" />
</div>
<div id="demo2"></div>
</div>
<script type="text/javascript" >
/***********************************
* scrollType:滚动类型
* 要出现滚动demo的height必须小于demo1的height+height/2
************************************/
var scrollType = 2;
var demo = document.getElementById("demo");
var demo1 = document.getElementById("demo1");
var demo2 = document.getElementById("demo2");
var speed = 10; //滚动速度值,值越大速度越慢
demo2.innerHTML = demo1.innerHTML //克隆demo2为demo1
function Marquee() {
switch(scrollType)
{
case 1: ScrollDown(); break;//向上滚动
case 2: ScrollTop(); break;//向下滚动
}
}
function ScrollDown() {
if (demo2.offsetTop - demo.scrollTop <= 0)
demo.scrollTop -= demo1.offsetHeight;
else
demo.scrollTop++
}
function ScrollTop() {
if(demo1.offsetTop-demo.scrollTop>=0)
demo.scrollTop+=demo2.offsetHeight
else
demo.scrollTop--
}
var MyMar = setInterval(Marquee, speed);
demo.onmouseover = function() { clearInterval(MyMar) }
demo.onmouseout = function() { MyMar = setInterval(Marquee, speed) }
</script>
-----------------------------------------------------------------------------------------
左右滚动
<div align="center" id="demo" style="overflow:hidden;height:33px;width:174px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="demo1">
<img src="images/button01.jpg" /><img src="images/button01.jpg" /><img src="images/button01.jpg" />
</td>
<td id="demo2"> </td>
</tr>
</table>
</div>
<script type="text/javascript" >
/***********************************
* scrollType:滚动类型
* 要出现滚动demo的width必须小于demo1的width+width/2
*
************************************/
var scrollType = 1;
var demo = document.getElementById("demo");
var demo1 = document.getElementById("demo1");
var demo2 = document.getElementById("demo2");
var speed = 10; //滚动速度值,值越大速度越慢
demo2.innerHTML = demo1.innerHTML //克隆demo2为demo1
function Marquee() {
switch(scrollType)
{
case 1: ScrollLeft(); break;//向左滚动
case 2: ScrollRight(); break;//向右滚动
}
}
function ScrollLeft() {
if (demo2.offsetWidth - demo.scrollLeft <= 0)
demo.scrollLeft -= demo1.offsetWidth
else
demo.scrollLeft++
}
function ScrollRight() {
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else
demo.scrollLeft--
}
var MyMar = setInterval(Marquee, speed);
demo.onmouseover = function() { clearInterval(MyMar) }
demo.onmouseout = function() { MyMar = setInterval(Marquee, speed) }
</script>