jquery抽奖程序

<script type="text/javascript" src="{JS_PATH}/aidazhe/game_zhuanpan.js"></script>
<script type="text/javascript">
    var runTime;//定时器
    var runStart=0;//色块位置
    var runSpeed=60;//速度
    var tt=1;//曲线运动当前时间
    var chouLength=10;//奖品数量
    var is_stop = 0;
    var run_stop;//定时器2
    $(function(){
        $("#chou-btn").click(function(){
            {if $_userid}
            suiji=$.ajax({url:"{APP_PATH}jifen.php",async:false,cache:false});
            suiji=suiji.responseText;
            $("#iframebg").show();
            runRotate(runStart);
            window.setTimeout(stopRotate(suiji),1000);
            check();
            {else}
            alert("您还未登录,请登录后再进行抽奖。");
            {/if}
        })
    })
    
    //检查
    function check() {
        window.clearInterval(run_stop);
        if (is_stop == 1) {
            check_stop();
        } else {
            run_stop = setInterval(function(){check();},500);
        }
    }
    
    //开始旋转
    function runRotate(i){
        clearInterval(runTime);
        $("#chou-lumps li").eq(i).addClass("current").siblings().removeClass("current");
        if(runStart<chouLength){
            runStart++;
        }else{
            runStart=0;
        }
        runTime=setInterval(function(){
            runRotate(runStart);
        },runSpeed);
    }
    //停止旋转
    function stopRotate(i){
        clearInterval(runTime);
        var cur=$("#chou-lumps li").index($("#chou-lumps li.current")[0]);
        var index=i-cur+33;
        var next=cur;
        if(next==chouLength){next=0;}
        easeOutQuad(index,next);
    }
    //减速旋转
    function easeOutQuad(index,cur) {
        clearInterval(runTime);
        $("#chou-lumps li").eq(cur).addClass("current").siblings().removeClass("current");
        if(runStart<10){
            runStart++;
        }else{
            runStart=0;
        }
        index--;
        if(index!=0){
            tt++;
            runTime=setInterval(function(){
                easeOutQuad(index,runStart);
            },easeOut(tt,60,120,25));
        }else{
            runSpeed=60;
            tt=1;
            $("#iframebg").hide();
            is_stop=1;
        }
    }
    //曲线算法,减速值
    function easeOut(t,b,c,d){
        return c*(t/=d)*t*t + b;
    }
    //判断是否停止
    function check_stop() {
        var jiangpin = parseInt(suiji) + 1 ;
        alert("您抽到了第" + jiangpin + "个奖品!");
        window.location.href="{APP_PATH}index.php?m=member&c=index&a=youxijifen&uid={$_userid}&aid="+suiji;
    }
</script>
<div id="chou-box" style="margin:10px auto;">
    <ul id="chou-lumps">
        <li class="lump0 current"></li>
        <li class="lump1"></li>
        <li class="lump2"></li>
        <li class="lump3"></li>
        <li class="lump4"></li>
        <li class="lump5"></li>
        <li class="lump6"></li>
        <li class="lump7"></li>
        <li class="lump8"></li>
        <li class="lump9"></li>
        <li class="lump10"></li>
    </ul>
    <div id="chou-btn"></div>
    <div id="iframebg"></div>
    {if !$_userid}
    <div id="login" style="color: white;">
        您还未登录,不能进行抽奖!<a href="{APP_PATH}loginbox.html?height=200;width=400" class="thickbox">点击登录</a>
    </div>
    {/if}
</div>

你可能感兴趣的:(jquery抽奖程序)