There is a code that sets the change of pictures:
var image_count = 7; var interval = 16000; var time_out = 5; var i = 0; var timeout; var opacity = 100; function change_image() { opacity--; var j = i + 1; var current_image = 'img_' + i; if (i == image_count) j = 1; var next_image = 'img_' + j; document.getElementById(current_image).style.opacity = opacity / 100; document.getElementById(current_image).style.filter = 'alpha(opacity=' + opacity + ')'; document.getElementById(next_image).style.opacity = (100 - opacity) / 100; document.getElementById(next_image).style.filter = 'alpha(opacity=' + (100 - opacity) + ')'; timeout = setTimeout('change_image()', time_out); if (opacity == 1) { opacity = 100; clearTimeout(timeout); } } setInterval(function () { i++; if (i > image_count) i = 1; change_image(); }, interval); Instead of stitching:
var i = 0; I added:
var i = Math.random(); function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } But for some reason it does not work. That is, when the variable i is zero, it takes the first image in the list and then changes it in a row. And I wanted him to take a random picture and then go in order in the list. Here is a list of pictures:
<img src="/images/fon/70.jpg" id="img_1" style="position: absolute;"> <img src="/images/fon/50.jpg" id="img_2" style="opacity: 0; filter: alpha(opacity=0); position: absolute;"> <img src="/images/fon/49.jpg" id="img_3" style="opacity: 0; filter: alpha(opacity=0); position: absolute;"> <img src="/images/fon/55.jpg" id="img_4" style="opacity: 0; filter: alpha(opacity=0); position: absolute;"> <img src="/images/fon/56.jpg" id="img_5" style="opacity: 0; filter: alpha(opacity=0); position: absolute;"> <img src="/images/fon/77.jpg" id="img_6" style="opacity: 0; filter: alpha(opacity=0); position: absolute;"> <img src="/images/fon/88.jpg" id="img_7" style="opacity: 0; filter: alpha(opacity=0); position: absolute;">
Math.random()and notgetRandomInt(0, 7)? - Grundy