dongsi5381 2015-11-05 14:50
浏览 65
已采纳

jQuery进度栏样式倒计时器

I am making a project where when I click the button a progress bar starts for a certain period usually 30 to 60 seconds. This progress bar is made in jquery and demo is available on this page http://www.jqueryscript.net/demo/Easy-jQuery-Progress-Bar-Timer-Plugin-For-Bootstrap-3-progressTimer/

I have implemented this on my project as it exactly suits my need. Now what I need to do is that when the timer completes the "Progress bar" and the "Do it!" but should hide automatically and display some another element say a captcha for verification. As I have a week hand on jquery I am not sure how to do it. Here is my code as well as the code of the "Progress bar script".

My page:

<!-- AD TIMER -->
<div>
<input type="hidden" id="restTime" value="<?php echo $ad_timer; ?>" disabled style="width: 50px; margin-left: 350px; margin-top: -70px; text-indent:10px" />
<button id="startProgressTimer" style="margin-top: -65Mpx; height: 45px; width: 90px; margin-left: 430px;">START</button>
<div id="progressTimer" style="width:400px; margin-left: 530px; margin-top: -34px"></div>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> 
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script> 
<script src="css/jquery.progressTimer.js"></script> 
<script>
            $("#startProgressTimer").click(function() {
                $("#progressTimer").progressTimer({
                    timeLimit: $("#restTime").val()
                });
            });
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-36251023-1']);
  _gaq.push(['_setDomainName', 'jqueryscript.net']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</div>
<!-- AD TIMER END -->

jquery.progressTimer.js

(function ($) {
    $.fn.progressTimer = function (options) {
        var settings = $.extend({}, $.fn.progressTimer.defaults, options);

        this.each(function () {
            $(this).empty();
            var barContainer = $("<div>").addClass("progress active progress-striped");
            var bar = $("<div>").addClass("progress-bar").addClass(settings.baseStyle)
                .attr("role", "progressbar")
                .attr("aria-valuenow", "0")
                .attr("aria-valuemin", "0")
                .attr("aria-valuemax", settings.timeLimit);

            bar.appendTo(barContainer);
            barContainer.appendTo($(this));

            var start = new Date();
            var limit = settings.timeLimit * 1000;
            var interval = window.setInterval(function () {
                var elapsed = new Date() - start;
                bar.width(((elapsed / limit) * 100) + "%");

                if (limit - elapsed <= 5000)
                    bar.removeClass(settings.baseStyle)
                       .removeClass(settings.completeStyle)
                       .addClass(settings.warningStyle);

                if (elapsed >= limit) {
                    window.clearInterval(interval);

                    bar.removeClass(settings.baseStyle)
                       .removeClass(settings.warningStyle)
                       .addClass(settings.completeStyle);

                    settings.onFinish.call(this);

                }

            }, 250);

        });

        return this;
    };

    $.fn.progressTimer.defaults = {
        timeLimit: 60,  //total number of seconds
        warningThreshold: 5,  //seconds remaining triggering switch to warning color
        onFinish: function () {},  //invoked once the timer expires
        baseStyle: '',  //bootstrap progress bar style at the beginning of the timer
        warningStyle: 'progress-bar-danger',  //bootstrap progress bar style in the warning phase
        completeStyle: 'progress-bar-success'  //bootstrap progress bar style at completion of timer
    };
}(jQuery));

What should I modify to make it work? Please help me experts..!

  • 写回答

1条回答 默认 最新

  • dtpt75860 2015-11-05 14:55
    关注

    Use onFinish event to add your function to hide elements :

    $("#startProgressTimer").click(function() {
          $("#progressTimer").progressTimer({
               timeLimit: $("#restTime").val(),
               onFinish: function(){
                    $('#startProgressTimer').hide();
                    $('#progressTimer').hide();
               }
          });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用