// Define a random integer function
function random(n){
return Math.floor(Math.random() * n);
}
// Define some variables, hide all images and show just one of them.
var transition_time = 500;
var waiting_time = 500;
var images = $('div#Slogan img');
var n = images.length;
var current = random(n);
images.hide();
images.eq(current).show();
// Periodically, we fadeOut the current image and fadeIn a random one
var interval_id = setInterval(function(){
images.eq(current).fadeOut(transition_time, function(){
current = random(n);
images.eq(current).fadeIn(transition_time);
});
}, 2 * transition_time + waiting_time);
// You can then stop the effect with:
// clearInterval(interval_id);
plugin s heavy。我們可以做得更簡單嗎? – 2010-08-18 11:28:08
我擔心它可能不夠簡單,如果你看看他們如何實現淡入淡出,他們基本上設置容器div的背景圖像,然後循環顯示和隱藏每個圖像(淡入淡出效果)。 – 2010-08-18 11:48:03