Change image in HTML page every few seconds

前端 未结 6 1225
死守一世寂寞
死守一世寂寞 2020-11-28 06:57

I want to change images every few seconds, this is my code:




        
6条回答
  •  孤独总比滥情好
    2020-11-28 07:18

    You can load the images at the beginning and change the css attributes to show every image.

    var images = array();
    for( url in your_urls_array ){
       var img = document.createElement( "img" );
       //here the image attributes ( width, height, position, etc )
       images.push( img );
    }
    
    function player( position )
    {
      images[position-1].style.display = "none" //be careful working with the first position
      images[position].style.display = "block";
      //reset position if needed
      timer = setTimeOut( "player( position )", time );
    }
    

提交回复
热议问题