jQuery抛洒金币效果

来源:https://www.sucaihuo.com/js/577.html 2015-11-28 05:29浏览(4740) 收藏

抛洒金币的效果主要是由jQuery的animate动画效果完成,也就是改变金币的运动轨迹,定时去执行,直到洒落到地面。
jQuery抛洒金币效果
分类:其它特效 > 抽奖 难易:初级
查看演示 下载资源 下载积分: 20 积分
关注公众号,免费赠送安装视频教程、环境和学习视频,后面会不断更新。

口袋和金币

<div class="kodai">
    <img src="images/kd2.png" class="full" />
    <img src="images/kd1.png" class="empty" />
</div>

点击口袋,抛洒金币效果

$('.item1 div.kodai').on('click', function() {

    if (clicked === false) {
        $('.full').css({
            'display': 'none'
        });
        $('.empty').css({
            'display': 'block'
        });
        clicked = true;

        $('.item1 .clipped-box').css({
            'display': 'block'
        });
        // Apply to each clipped-box div.
        $('.clipped-box img').each(function() {
            var v = rand(120, 90),
                    angle = rand(80, 89),
                    theta = (angle * Math.PI) / 180,
                    g = -9.8;

            // $(this) as self
            var self = $(this);
            var t = 0,
                    z, r, nx, ny,
                    totalt = 10;
            var negate = [1, -1, 0],
                    direction = negate[Math.floor(Math.random() * negate.length)];

            var randDeg = rand(-5, 10),
                    randScale = rand(0.9, 1.1),
                    randDeg2 = rand(30, 5);

            // And apply those
            $(this).css({
                'transform': 'scale(' + randScale + ') skew(' + randDeg + 'deg) rotateZ(' + randDeg2 + 'deg)'
            });

            // Set an interval
            z = setInterval(function() {
                var ux = (Math.cos(theta) * v) * direction;
                var uy = (Math.sin(theta) * v) - ((-g) * t);
                nx = (ux * t);
                ny = (uy * t) + (0.25 * (g) * Math.pow(t, 2));
                if (ny < -40) {
                    ny = -40;
                }
                //$("#html").html("g:" + g + "bottom:" + ny + "left:" + nx + "direction:" + direction);
                $(self).css({
                    'bottom': (ny) + 'px',
                    'left': (nx) + 'px'
                });
                // Increase the time by 0.10
                t = t + 0.10;

                //跳出循环
                if (t > totalt) {
                    clicked = false;
                    first = true;
                    clearInterval(z);
                }
            }, 20);
        });
    }
});
标签: 抽奖金币
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2