切换主图 [英] switch main picture
问题描述
您好,
我有一个带主图片的html页面,但我希望每3秒钟主图片切换
到一张新主图片。我怎么能在java脚本中这样做。
John
Hello,
I have a html page with a main picture but I want the main picture switch
every 3 seconds to a new main pictures. How can I do this in java script.
John
推荐答案
Bruintje Beer在5上说了以下内容/ 22/2006 12:55 AM:
Bruintje Beer said the following on 5/22/2006 12:55 AM:
你好,
我有一个主图片的html页面,但我想要每3秒钟一次主画面切换
到一个新的主要图片。我怎么能在java脚本中这样做。
Hello,
I have a html page with a main picture but I want the main picture switch
every 3 seconds to a new main pictures. How can I do this in java script.
window.interval
document.images [''mainImage'']。src = newImageName ;
搜索档案,以上是您需要了解的内容。不,我不会为你写代码,我已经写了足够的代码了。
-
Randy
comp.lang.javascript常见问题 - http:// jibbering。 com / faq &新闻组每周
Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /
window.interval
document.images[''mainImage''].src = newImageName;
Search the archives, the above is what you need to know. And no, I won''t
write the code for you, I have written that code enough already.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
>我有一个带有主图片的html页面,但是我希望每3秒钟主图片切换
> I have a html page with a main picture but I want the main picture switch
到新的主图片。我怎样才能在java脚本中执行此操作。
every 3 seconds to a new main pictures. How can I do this in java script.
这里是一个非常简单的解决方案我想出了:
var slideIntv = false; //这个间隔会切换你的图像
var slides = [''one.PNG'',''two.PNG'',''three.PNG'']; //数组保持
图像的路径名
var ctr = parseInt(0); //这将指向图像的路径名
你想要显示
函数startSlideShow(){
slideIntv = setInterval(function(){
ctr =(ctr + 1)%3; //转到下一张幻灯片
document.images [' 'main-image'']。src = slides [ctr]; //设置主图像的
来源,其中img id属性为id =" main-image"
},3000); //每3000毫秒= 3秒
}
只需调用此函数onload。
here''s a really simple solution i came up with:
var slideIntv = false; //this interval will switch your images
var slides = [''one.PNG'', ''two.PNG'', ''three.PNG'']; //array holding
pathnames of images
var ctr = parseInt(0); //this will point to the pathname of the image
you want displayed
function startSlideShow() {
slideIntv = setInterval(function() {
ctr = (ctr + 1) % 3; //go to next slide
document.images[''main-image''].src = slides[ctr]; //set the
source of the main image where img id attribute is id="main-image"
}, 3000); //every 3000 milliseconds = 3 seconds
}
Just call this function onload.
>
Walton在2006年5月22日下午3:04发表以下内容:
Walton said the following on 5/22/2006 3:04 PM:
我有一个主图片的html页面,但我想要主图片每隔3秒切换一次新的主图片。我怎样才能在java脚本中执行此操作。
这是一个非常简单的解决方案:
var slideIntv = false; //这个间隔会切换你的图像
var slides = [''one.PNG'',''two.PNG'',''three.PNG'']; //数组控件
图像的路径名
I have a html page with a main picture but I want the main picture switch
every 3 seconds to a new main pictures. How can I do this in java script.
here''s a really simple solution i came up with:
var slideIntv = false; //this interval will switch your images
var slides = [''one.PNG'', ''two.PNG'', ''three.PNG'']; //array holding
pathnames of images
想知道为什么IE用户看不到图像?
var ctr = parseInt函数(0); //这将指向图像的路径名
你想要显示
为什么你解析为零?
var ctr = 0;
函数startSlideShow(){
slideIntv = setInterval(function(){
ctr =(ctr + 1) %3; //转到下一张幻灯片
document.images [''main-image'']。src = slides [ctr]; //设置主图像的来源,其中img id属性是id =" main-image"
您的评论不正确,图片集合起作用名称
属性
},3000); //每3000毫秒= 3秒
}
函数startSlideShow(){
ctr ++;
if(ctr == slides.length){ctr = 0}
document.images [''main-image'']。src = slides [(ctr + 1)%3;] ;
}
slideIntv = window.setInterval(slideShow,3000);
< button onclick =" window。 clearInterval(slideIntv)">停止幻灯片演示
< / button>
为什么要让它变得更难?
只需调用此函数onload。
And wonder why IE users don''t see images?
var ctr = parseInt(0); //this will point to the pathname of the image
you want displayed
Why are you parseInt''ing zero?
var ctr=0;
function startSlideShow() {
slideIntv = setInterval(function() {
ctr = (ctr + 1) % 3; //go to next slide
document.images[''main-image''].src = slides[ctr]; //set the
source of the main image where img id attribute is id="main-image"
Your comment is incorrect, the images collection works off the name
attribute
}, 3000); //every 3000 milliseconds = 3 seconds
}
function startSlideShow() {
ctr++;
if (ctr == slides.length){ctr = 0}
document.images[''main-image''].src = slides[(ctr + 1) % 3;];
}
slideIntv = window.setInterval(slideShow,3000);
<button onclick="window.clearInterval(slideIntv)">Stop the Slideshow
</button>
Why make it harder than it is?
Just call this function onload.
无需,只需在函数外设置setInterval即可。
-
Randy
comp.lang.javascript常见问题 - http:// jibbering .com / faq &新闻组每周
Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /
No need to, just set setInterval outside the function.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
这篇关于切换主图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!