Js slide show image sample code

  • 2020-03-26 23:50:42
  • OfStack

1, add the following elements to the page. Displays a list of file Settings.
 
<select id="img_date" style="width: 100%; margin-top: 10px; height: 50%;" size="20"> 
<option value=" The image url"> Image name </option> 
</select> 

2, the method of playing the list of files. This is done by walking through the list of files and displaying the images in the appropriate image container.

Traversal methods can be called with a delayed method: window.setinterval ("PlayPics()", speed);
 
 
function PlayPics() 
{ 
var sel = document.getElementById("img_date"); 
if(sel.length==0)//Return without pictures
{ 
return; 
} 
else 
{ 
if(sel.selectedIndex>0)//When the selected subscript is greater than 0, the previous image item is selected.
{ 
sel.options[sel.selectedIndex-1].selected=true; 
} 
else{//If the subscript of the selected item is 0, the last image is set to be selected.
sel.options[sel.length-1].selected=true; 
} 
ChangePic(sel.options[sel.selectedIndex].value);//Gets the selected image and sets the image url to the appropriate image container.

//This method can be modified to suit your needs.
} 
}; 

Related articles: