怎么用javascript做网站做出图片滚动循环的效果?
就是那种七八个图片float:left排列、向右移动、左边出来…是缓慢移动不是一张图片一张图片的动、谢谢师兄哈。...
就是那种七八个图片float:left排列、向右移动、左边出来…是缓慢移动不是一张图片一张图片的动、谢谢师兄哈。
展开
2个回答
展开全部
这个,是我自己做了个:
<!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>替代Marquee滚动效果</title>
<style type="text/css">
.Mar
{
margin:8px auto;
background: #FFF;
overflow: hidden;
border: 1px dashed #CCC;
width: 800px; /*页面滚动需要显示的宽度*/
}
.Mar img
{
border: 3px solid #F2F2F2;
width: 124px;
height: 93px;
}
.inMar
{
float: left;
width: 3500px; /*能在一行放下所有滚动的图片的总宽度*2 像素值或者百分比*/
}
</style>
</head>
<body>
<div id="Mar" class="Mar">
<div id="inMar" class="inMar">
<div id="Mar1" style="float:left;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="img/c (1).jpg"/><br />轿车:1</td>
<td><img src="img/c (2).jpg"/><br />轿车:2</td>
<td><img src="img/c (3).jpg"/><br />轿车:3</td>
<td><img src="img/c (4).jpg"/><br />轿车:4</td>
<td><img src="img/c (5).jpg"/><br />轿车:5</td>
<td><img src="img/c (6).jpg"/><br />轿车:6</td>
<td><img src="img/c (7).jpg"/><br />轿车:7</td>
<td><img src="img/c (8).jpg"/><br />轿车:8</td>
<td><img src="img/c (9).jpg"/><br />轿车:9</td>
<td><img src="img/c (10).jpg"/><br />轿车:10</td>
<td><img src="img/c (11).jpg"/><br />轿车:11</td>
<td><img src="img/c (12).jpg"/><br />轿车:12</td>
</tr>
</table>
</div>
<div id="Mar2" style="float:left;">
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
var speed = 12; //数字越小速度越快
var step = 2;//步进
var nImgWidth = 130;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
var div2 = document.getElementById("Mar2");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if(div.scrollLeft%nImgWidth == 0) {//每一张图片就停留,如果要连续就去掉这点代码
div.scrollLeft += step;
step = 0;
window.setTimeout("set(2)", 2000);
}
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft += step;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
function set(i) {
i = parseInt(i);
step = i;
}
</script>
</body>
</html>
<!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>替代Marquee滚动效果</title>
<style type="text/css">
.Mar
{
margin:8px auto;
background: #FFF;
overflow: hidden;
border: 1px dashed #CCC;
width: 800px; /*页面滚动需要显示的宽度*/
}
.Mar img
{
border: 3px solid #F2F2F2;
width: 124px;
height: 93px;
}
.inMar
{
float: left;
width: 3500px; /*能在一行放下所有滚动的图片的总宽度*2 像素值或者百分比*/
}
</style>
</head>
<body>
<div id="Mar" class="Mar">
<div id="inMar" class="inMar">
<div id="Mar1" style="float:left;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="img/c (1).jpg"/><br />轿车:1</td>
<td><img src="img/c (2).jpg"/><br />轿车:2</td>
<td><img src="img/c (3).jpg"/><br />轿车:3</td>
<td><img src="img/c (4).jpg"/><br />轿车:4</td>
<td><img src="img/c (5).jpg"/><br />轿车:5</td>
<td><img src="img/c (6).jpg"/><br />轿车:6</td>
<td><img src="img/c (7).jpg"/><br />轿车:7</td>
<td><img src="img/c (8).jpg"/><br />轿车:8</td>
<td><img src="img/c (9).jpg"/><br />轿车:9</td>
<td><img src="img/c (10).jpg"/><br />轿车:10</td>
<td><img src="img/c (11).jpg"/><br />轿车:11</td>
<td><img src="img/c (12).jpg"/><br />轿车:12</td>
</tr>
</table>
</div>
<div id="Mar2" style="float:left;">
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
var speed = 12; //数字越小速度越快
var step = 2;//步进
var nImgWidth = 130;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
var div2 = document.getElementById("Mar2");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if(div.scrollLeft%nImgWidth == 0) {//每一张图片就停留,如果要连续就去掉这点代码
div.scrollLeft += step;
step = 0;
window.setTimeout("set(2)", 2000);
}
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft += step;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
function set(i) {
i = parseInt(i);
step = i;
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询