Возможно, вы захотите сохранить URL-адреса изображений в переменной (или получить их из вашего div
и затем очистить div
), скажем
var images = ['x.jpg', 'y.jpg', 'z.jpg'];
(или даже лучше - выполнить некоторую предварительную загрузку),Затем выполните случайную сортировку
function randomOrd(a,b)
{
return (Math.round(Math.random())-0.5);
}
images.sort(randomOrd);
, затем динамически добавьте изображения
for (var i in images)
{
$('#myslides').append('<img src="'+images[i]+'" />');
}
и затем выполните слайд-шоу.Окончательный сценарий может выглядеть так:
<script>
function randOrd(a,b)
{
return (Math.round(Math.random())-0.5);
}
$(document).ready(function(){
var images = [];
/* retrieve images */
$('div#myslides img').each(function(){
images.push($(this));
});
/* clear the div */
$('div#myslides').empty();
/* do the random sort of images */
images.sort(randOrd);
/* append to the div sorted images */
for (var i in images)
{
$('div#myslides').append(images[i]);
}
/* do the slideshow */
$('#myslides').cycle({
fx: 'fade',
speed: 2000,
timeout: 2000
});
});
</script>