用jquery淡入并淡出随机

时间:2011-04-14 17:49:26

标签: jquery random fade

最近我被要求做这个效果

http://mobile.bebitalia.com/home.do

但它是用scriptaculus创建的,我需要以某种方式使用jquery来实现它。

我找到了这个例子,但它是中途

http://jsfiddle.net/5rkEw/

淡出完成后,你可以帮助我做淡出效果吗?

2 个答案:

答案 0 :(得分:3)

我正在整理一个小提琴,但你可以尝试使用类似的标记作为你给出的例子

// Translated from scriptaculus
// http://mobile.bebitalia.com/home.do

function hideCube() {
$('#gctu1w_bg').show('slow');
$('.cube').each(function(index, element) {
    var sleepTime = Math.floor(Math.random() * 2000);
    var t = setTimeout(function() {
        var d = Math.floor(Math.random() * 2000);
        $(element).fadeTo(d, 0);
    }, sleepTime);
});
}

$(function() {

$('.cube').each(function(index, element) {
    var sleepTime = Math.floor(Math.random() * 2000);
    var t = setTimeout(function() {
        var d = Math.floor(Math.random() * 1000);
        $(element).fadeTo(d, 0.99);
    }, sleepTime);
});

var h = setTimeout(hideCube, 4000);

});

http://jsfiddle.net/nickywaites/GBhMw/

答案 1 :(得分:1)

这是一个很好的解决方案:

fadeInout = {
    init: function() {
        v = $("#blocks > li").css('visibility', 'hidden'),
        cur = 0,
        rem = 0;
        for (var j, x, i = v.length; i; 
             j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
        //other startup code
        return this;
    },

    fades: function() {
        this.fadein();
    },
    fadein: function() {
        v.eq(cur++).css('visibility', 'visible').hide().fadeIn();
        if (cur != v.length) setTimeout(fadeInout.fadein, 50);
        else setTimeout(fadeInout.fadeout, 100);
    },
    fadeout: function() {
        v.eq(rem++).css('visibility', 'none').fadeOut().show();
        if (rem != v.length) setTimeout(fadeInout.fadeout, 50);
    }

}

fadeInout.init().fades();

这是显示它的小提琴:http://jsfiddle.net/maniator/rcts4/