javascript setTimer jQuery中的幻灯片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript setTimer jQuery中的幻灯片相关的知识,希望对你有一定的参考价值。

// Slideshow Activity
// Students: follow the instructions below:

// TODO: Put links to our images in this image array.
var images = ["images/bootstrap.png",
"images/github-logo.jpg",
"images/logo_JavaScript.png"];

// Variable showImage will hold the setInterval when we start the slideshow
var showImage;

// Count will keep track of the index of the currently displaying picture.
var count = 0;

// TODO: Use jQuery to run "startSlideshow" when we click the "start" button.
$("#start").on("click",function(){
  startSlideshow();
});
// TODO: Use jQuery to run "stopSlideshow" when we click the "stop" button.
$("#stop").on("click",function(){
  stopSlideshow();
});

// This function will replace display whatever image it's given
// in the 'src' attribute of the img tag.
function displayImage() {
  $("#image-holder").html("<img src=" + images[count] + " width='400px'>");
}

function nextImage() {

  // TODO: Increment the count by 1.
count++;

  // TODO: Show the loading gif in the "image-holder" div.

  $("#image-holder").html("<img src=" + "images/loading.gif" + " width='400px'>");

  // TODO: Use a setTimeout to run displayImage after 1 second.
setTimeout(displayImage,1000);

  // TODO: If the count is the same as the length of the image array, reset the count to 0.
if(count==images.length){
  count=0;
}

}
function startSlideshow() {
  // TODO: Use showImage to hold the setInterval to run nextImage.
showImage=setInterval(nextImage,1500);
}
function stopSlideshow() {

  // TODO: Put our clearInterval here:
clearInterval(showImage);

}

// This will run the display image function as soon as the page loads.
displayImage();

以上是关于javascript setTimer jQuery中的幻灯片的主要内容,如果未能解决你的问题,请参考以下文章

javascript 【ver2】可视范囲に入ってたらfadeIn※要jQuer

javascript tamañojavascriptstring dimensiones dinamicamente ancho texto nodo dom elemento jquer

jquer 事件,选择器,dom操作

MFC 中,全局SetTimer函数怎么用?

jQuery了解

SetTimer