<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片滚动</title>
</head>
<body>
<style type="text/css">
<!--
#demo {
margin-left:auto;
margin-right:auto;
background: #FFF;
overflow:hidden; //内容溢出的时候,溢出的内容隐藏起来
border: 1px dashed #CCC;
width: 700px;
}
#demo img {
border: 3px solid #F2F2F2;
height:138px;//为了应对不同大小的图片,给图片设置小一点的规格
width:104px;
}
#indemo {
float: left;
width: 800%;
}
#demo1 {
float: left;
}
#demo2 {
float: left;
}
-->
</style>
<div id="demo">
<div id="indemo">
<div id="demo1">
<a href="#"><img src="images/001.jpg" border="0" /></a>
<a href="#"><img src="images/002.jpg" border="0" /></a>
<a href="#"><img src="images/003.jpg" border="0" /></a>
<a href="#"><img src="images/004.jpg" border="0" /></a>
<a href="#"><img src="images/005.jpg" border="0" /></a>
</div>
<div id="demo2"></div>
</div>
</div>
<script>
<!--
var speed=30; ///数字小,速度快。毫秒为单位
var tab=document.getElementById("demo");
var tab1=document.getElementById("demo1");
var tab2=document.getElementById("demo2");
tab2.innerHTML=tab1.innerHTML;
function Marquee(){
if(tab2.offsetWidth-tab.scrollLeft<=0) //offsetWidth是获取demo2元素的宽度 tab.scrollLeft是指demo在滚动时隐藏在页面左侧的宽度
tab.scrollLeft-=tab1.offsetWidth //当滚动至demo1与demo2交界时demo跳到最顶端
else{
tab.scrollLeft++; //表示像做偏移量+1,即像左移动一个像素
}
}
var MyMar=setInterval(Marquee,speed); //setInterval(函数或代码串,时间),每30毫秒调用一次marquee函数,除非调用clearinterval()函数停止或浏览器关闭
tab.onmouseover=function() {clearInterval(MyMar)}; //鼠标放在上面,停止滚动
tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)}; //鼠标移出,继续
-->
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片滚动</title>
</head>
<body>
<style type="text/css">
<!--
#demo {
margin-left:auto;
margin-right:auto;
background: #FFF;
overflow:hidden; //内容溢出的时候,溢出的内容隐藏起来
border: 1px dashed #CCC;
width: 700px;
}
#demo img {
border: 3px solid #F2F2F2;
height:138px;//为了应对不同大小的图片,给图片设置小一点的规格
width:104px;
}
#indemo {
float: left;
width: 800%;
}
#demo1 {
float: left;
}
#demo2 {
float: left;
}
-->
</style>
<div id="demo">
<div id="indemo">
<div id="demo1">
<a href="#"><img src="images/001.jpg" border="0" /></a>
<a href="#"><img src="images/002.jpg" border="0" /></a>
<a href="#"><img src="images/003.jpg" border="0" /></a>
<a href="#"><img src="images/004.jpg" border="0" /></a>
<a href="#"><img src="images/005.jpg" border="0" /></a>
</div>
<div id="demo2"></div>
</div>
</div>
<script>
<!--
var speed=30; ///数字小,速度快。毫秒为单位
var tab=document.getElementById("demo");
var tab1=document.getElementById("demo1");
var tab2=document.getElementById("demo2");
tab2.innerHTML=tab1.innerHTML;
function Marquee(){
if(tab2.offsetWidth-tab.scrollLeft<=0) //offsetWidth是获取demo2元素的宽度 tab.scrollLeft是指demo在滚动时隐藏在页面左侧的宽度
tab.scrollLeft-=tab1.offsetWidth //当滚动至demo1与demo2交界时demo跳到最顶端
else{
tab.scrollLeft++; //表示像做偏移量+1,即像左移动一个像素
}
}
var MyMar=setInterval(Marquee,speed); //setInterval(函数或代码串,时间),每30毫秒调用一次marquee函数,除非调用clearinterval()函数停止或浏览器关闭
tab.onmouseover=function() {clearInterval(MyMar)}; //鼠标放在上面,停止滚动
tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)}; //鼠标移出,继续
-->
</script>
</body>
</html>