zoukankan      html  css  js  c++  java
  • 抽奖转盘(jqueryrotate.js)

    jqueryrotate.js抽奖转盘,使用方便,兼容各浏览器,效果如下图

    <!DOCTYPE>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>转盘抽奖</title>
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/Rotate.js"></script>
    <style>
    *{padding:0; margin:0;}
    .lotteryMain{ width:100%; padding:20px 0; }
    .lotteryBg{ width:520px; height:520px; margin:0 auto; background:url(images/lotteryBg.jpg) no-repeat; position:relative; overflow:hidden;}
    #run{ width:153px; height:214px; position:absolute; left:50%; top:50%;  margin-left:-76px; margin-top:-107px; z-index:1; transform:rotate(0deg); -ms-transform:rotate(0deg); }
    #btn_run{ width:125px; height:125px; background:url(images/btn_start.png) no-repeat; border:none; outline:none; position:absolute; left:50%; top:50%; margin-left:-62px; margin-top:-62px; z-index:2;cursor:pointer;}
    </style>
    </head>
    
    <body>
    <section class="lotteryMain">
        <div class="lotteryBg">
            <img id="run" src="images/start.png" />
            <input id="btn_run" type="button" value="" />
        </div>
        <div id="results">
        
        </div>
    </section>  
    <script>
    $(function(){ 
         $("#btn_run").click(function(){
            $("#btn_run").attr('disabled',true).css("cursor","default"); 
            lottery(); 
        });
    }); 
    function lottery(){ 
        $.ajax({ 
            type: 'get', 
            url: 'json2.js', 
            dataType: 'json', 
            cache: false, 
            error: function(){return false;}, 
            success:function(obj){
                    $("#run").rotate({ 
                        duration:3000, //转动时间 
                        angle: 0, //默认角度
                        animateTo:360*6+obj.rotate, //转动角度 
                        easing: $.easing.easeOutSine, 
                        callback: function(){ 
                            alert(obj.results); 
                        $("#btn_run").attr('disabled',false).css("cursor","pointer"); 
                        } 
                    });
            } 
        }); 
    };
        
    </script>  
    </body>
    </html>
    View Code

    json.js里是个json对象,模拟服务器返回的数据,{"isHasChance":"true","rotate":240,"results":"iphone 5s!!"}

    demo下载(放在IIS上运行)

  • 相关阅读:
    给自己一个书单
    pureMVC学习之一
    泛型与无聊
    队列与DelphiXe新语法
    有道理的前端
    具备 jQuery 经验的人如何学习AngularJS(附:学习路径)
    Blogging with github Pages
    Cookie/Session机制
    通往全栈工程师的捷径 —— react
    女生应该找个有独立博客的男朋友
  • 原文地址:https://www.cnblogs.com/xiaomou2014/p/4063905.html
Copyright © 2011-2022 走看看