js-红包雨

function redRain(){
    var redPacketCreateTime = 200
    var redPacket = $('<div class="reb-bag"></div>')
    var docWidth = $(document).width()
    var redBoxWith = $('.red-real-box').width()
    var redBoxHeight = $('.red-real-box').height()
    setInterval(function () {
        var startLeft = Math.random()*redBoxWith
        var endLeft = Math.random()*redBoxWith
        var redSpeed = 3000
        var that = redPacket.clone()
        that.appendTo($('.red-real-box'))
        that.css({
            'left':startLeft,
            'top':"-100px"
        })
        if(startLeft>redBoxWith-120){
            return;
        }
        that.animate({
            'left':startLeft,
            'top':redBoxHeight
        },{
            duration:redSpeed,
            step:function () {},
            complete:function () {
                $(this).remove()
            }
        })
    },redPacketCreateTime)
}

猜你喜欢

转载自www.cnblogs.com/huang-gua/p/9468966.html