Javascript:循环图像

时间:2016-07-16 18:36:55

标签: javascript jquery html

我有一系列图像,我想无限循环,但我似乎无法理解逻辑,这是我的尝试:

http://jsfiddle.net/jzhang172/RwjFX/4/

var imagesArray = ["http://vignette2.wikia.nocookie.net/pokemon/images/e/ef/025Pikachu_Pokemon_Mystery_Dungeon_Red_and_Blue_Rescue_Teams.png/revision/latest?cb=20150105233050",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full//007.png",
"http://assets.pokemon.com/assets/cms2/img/pokedex/full/001.png",
"http://www.pokemonxy.com/_ui/img/_en/art/Fennekin-Pokemon-X-and-Y.jpg",
"http://www.pokemon20.com/assets/img/mythical/arceus/poke_arceus.png"];

var count = 0;
  
  
    var loopImages = function(count){

            $('#firstStar').fadeIn(1500, function(){

            if (count=0){
            $('img').attr('src', imagesArray[1]);
            }

             $('#firstStar').delay(4000).fadeOut(1500, loopImages(count));           
           });
           count++;
           console.log('Ending Count:'+count);
      }
   
   
   loopImages(count); //Step 1: Initiate Loop, passing count, starting at 0;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="https://www.kingdomhearts.com/2_8/images/logos/kingdom_hearts_birth_by_sleep_logo.png" id="firstStar">

1 个答案:

答案 0 :(得分:1)

我已编辑代码以使其正常工作:http://jsfiddle.net/RwjFX/5/

请特别注意使用modulo (%)运算符和.bind函数。