图片自动切换js代码,如何才能让他自动循环?
如题,懂的帮我看一下,代码如下:1.会自动切换,但是不会自动循环,要让他自动循环该怎么改?2.能否实现给这几张图片加上超链接?<SCRIPT>varNowFrame=1;...
如题,懂的帮我看一下,代码如下:
1.会自动切换,但是不会自动循环,要让他自动循环该怎么改?
2.能否实现给这几张图片加上超链接?
<SCRIPT>
var NowFrame = 1;
var MaxFrame = 5;
var bStart = 0;
function fnToggle() {
var next = NowFrame + 1;
if(next == MaxFrame+1)
{
NowFrame = MaxFrame;
next = 1;
}
if(bStart == 0)
{
bStart = 1;
setTimeout('fnToggle()', 1000);
return;
}
else
{
oTransContainer.filters[0].Apply();
document.images['oDIV'+next].style.display = "";
document.images['oDIV'+NowFrame].style.display = "none";
oTransContainer.filters[0].Play(duration=5);
if(NowFrame == MaxFrame)
NowFrame = 1;
else
NowFrame++;
} setTimeout('fnToggle()', 6000);
}
fnToggle();
</SCRIPT>
<DIV id=oTransContainer style="FILTER: progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0, wipeStyle=0, motion='forward');">
<IMG id=oDIV1 style=" DISPLAY: yes;" src="images/banner/01.jpg">
<IMG id=oDIV2 style=" DISPLAY: none;" src="images/banner/02.jpg">
<IMG id=oDIV3 style=" DISPLAY: none;" src="images/banner/03.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/04.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/05.jpg">
</DIV> 展开
1.会自动切换,但是不会自动循环,要让他自动循环该怎么改?
2.能否实现给这几张图片加上超链接?
<SCRIPT>
var NowFrame = 1;
var MaxFrame = 5;
var bStart = 0;
function fnToggle() {
var next = NowFrame + 1;
if(next == MaxFrame+1)
{
NowFrame = MaxFrame;
next = 1;
}
if(bStart == 0)
{
bStart = 1;
setTimeout('fnToggle()', 1000);
return;
}
else
{
oTransContainer.filters[0].Apply();
document.images['oDIV'+next].style.display = "";
document.images['oDIV'+NowFrame].style.display = "none";
oTransContainer.filters[0].Play(duration=5);
if(NowFrame == MaxFrame)
NowFrame = 1;
else
NowFrame++;
} setTimeout('fnToggle()', 6000);
}
fnToggle();
</SCRIPT>
<DIV id=oTransContainer style="FILTER: progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0, wipeStyle=0, motion='forward');">
<IMG id=oDIV1 style=" DISPLAY: yes;" src="images/banner/01.jpg">
<IMG id=oDIV2 style=" DISPLAY: none;" src="images/banner/02.jpg">
<IMG id=oDIV3 style=" DISPLAY: none;" src="images/banner/03.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/04.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/05.jpg">
</DIV> 展开
4个回答
2011-08-31
展开全部
简单改了下,本地IE测试成功。注意我用的图片路径和你不太一样
<html>
<style type="text/css">
</style>
<SCRIPT>
var NowFrame = 0;
var MaxFrame = 5;
var bStart = 0;
function fnToggle() {
NowFrame = (NowFrame++) % MaxFrame;
oTransContainer.filters[0].Apply();
document.getElementById('oDIV'+NowFrame).style.display = "block";
oTransContainer.filters[0].Play(duration=2);
for(var i=0;i<MaxFrame;i++){
if(i!= NowFrame) {
document.getElementById('oDIV'+i).style.display = "none";
}
}
}
setInterval('fnToggle()', 3000);
</SCRIPT>
<body>
<DIV id="oTransContainer" style="width: 640px; height: 480px; filter:progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=0,motion='forward'">
<div id="oDIV0" style=" DISPLAY: yes;" ><IMG src="IMG_001.jpg"></div>
<div id="oDIV1" style=" DISPLAY: none;"><IMG src="IMG_002.jpg"></div>
<div id="oDIV2" style=" DISPLAY: none;"><IMG src="IMG_003.jpg"></div>
<div id="oDIV3" style=" DISPLAY: none;"><IMG src="IMG_004.jpg"></div>
<div id="oDIV4" style=" DISPLAY: none;"><IMG src="IMG_005.jpg"></div>
</DIV>
</body>
</html>
<html>
<style type="text/css">
</style>
<SCRIPT>
var NowFrame = 0;
var MaxFrame = 5;
var bStart = 0;
function fnToggle() {
NowFrame = (NowFrame++) % MaxFrame;
oTransContainer.filters[0].Apply();
document.getElementById('oDIV'+NowFrame).style.display = "block";
oTransContainer.filters[0].Play(duration=2);
for(var i=0;i<MaxFrame;i++){
if(i!= NowFrame) {
document.getElementById('oDIV'+i).style.display = "none";
}
}
}
setInterval('fnToggle()', 3000);
</SCRIPT>
<body>
<DIV id="oTransContainer" style="width: 640px; height: 480px; filter:progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=0,motion='forward'">
<div id="oDIV0" style=" DISPLAY: yes;" ><IMG src="IMG_001.jpg"></div>
<div id="oDIV1" style=" DISPLAY: none;"><IMG src="IMG_002.jpg"></div>
<div id="oDIV2" style=" DISPLAY: none;"><IMG src="IMG_003.jpg"></div>
<div id="oDIV3" style=" DISPLAY: none;"><IMG src="IMG_004.jpg"></div>
<div id="oDIV4" style=" DISPLAY: none;"><IMG src="IMG_005.jpg"></div>
</DIV>
</body>
</html>
展开全部
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/05.jpg">
</DIV>
id冲突,改为:
<IMG id=oDIV5 style=" DISPLAY: none;" src="images/banner/05.jpg">
</DIV>
</DIV>
id冲突,改为:
<IMG id=oDIV5 style=" DISPLAY: none;" src="images/banner/05.jpg">
</DIV>
追问
嗯,谢谢了。那如果给图片加上超链接会麻烦么?
追答
var NowFrame = 1;
var MaxFrame = 5;
var bStart = 0;
var aLink = document.getElementById("imh");
var aLnkArr = new Array();
//aLnkArr[0]="你的链接1";
aLnkArr[1]="你的链接1";
aLnkArr[2]="你的链接2";
aLnkArr[3]="你的链接3";
aLnkArr[4]="你的链接4";
aLnkArr[5]="你的链接5";
function fnToggle() {
aLink.href = aLnkArr[NowFrame];
var next = NowFrame + 1;
if(next == MaxFrame+1)
{
NowFrame = MaxFrame;
next = 1;
}
if(bStart == 0)
{
bStart = 1;
setTimeout('fnToggle()', 1000);
return;
}
else
{
oTransContainer.filters[0].Apply();
document.images['oDIV'+next].style.display = "";
document.images['oDIV'+NowFrame].style.display = "none";
oTransContainer.filters[0].Play(duration=5);
if(NowFrame == MaxFrame)
NowFrame = 1;
else
NowFrame++;
} setTimeout('fnToggle()', 6000);
}
fnToggle();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我怎么看时循环的
<IMG id=oDIV1 style=" DISPLAY: yes;" src="images/banner/01.jpg">
<IMG id=oDIV2 style=" DISPLAY: none;" src="images/banner/02.jpg">
<IMG id=oDIV3 style=" DISPLAY: none;" src="images/banner/03.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/04.jpg">
<IMG id=oDIV5 style=" DISPLAY: none;" src="images/banner/05.jpg">//本来是4改5...
</DIV>
IE可以动,ff动都不动的...
<IMG id=oDIV1 style=" DISPLAY: yes;" src="images/banner/01.jpg">
<IMG id=oDIV2 style=" DISPLAY: none;" src="images/banner/02.jpg">
<IMG id=oDIV3 style=" DISPLAY: none;" src="images/banner/03.jpg">
<IMG id=oDIV4 style=" DISPLAY: none;" src="images/banner/04.jpg">
<IMG id=oDIV5 style=" DISPLAY: none;" src="images/banner/05.jpg">//本来是4改5...
</DIV>
IE可以动,ff动都不动的...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你说的 循环什么意思
怎么个循环法啊 说具体点
怎么个循环法啊 说具体点
追问
= =|| 切换到最后一张的时候 又自动从第一张开始... 此谓循环
追答
既然 楼下的都写了,这里我就不写了
你试试他们的把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询