在倒计时结束时隐藏div

时间:2015-02-14 22:55:13

标签: javascript jquery timer hide countdown

这是一个倒计时脚本,它运行正常。我想在倒计时结束时隐藏#mydiv。你能帮我做一下吗?

谢谢大家

<div data-countdown="2015/02/28 02:18:26"></div>

<script type="text/javascript">
 $('[data-countdown]').each(function() {
   var $this = $(this), finalDate = $(this).data('countdown');
   $this.countdown(finalDate, function(event) {     
   $this.html(event.strftime('%D gün %H:%M:%S'));
   });
 });
</script>

3 个答案:

答案 0 :(得分:0)

从github文档页面获得语法:

$this.countdown(finalDate)
    .on('update.countdown', function(event) { $this.html(event.strftime('%D gün %H:%M:%S')); })
    .on('finish.countdown', function() { $('#mydiv').hide(); });

http://api.jquery.com/hide/

http://hilios.github.io/jQuery.countdown/documentation.html

编辑: 刚刚注意到文档说:

  

请注意,应该在命名空间中注册所有事件   * .countdown

<!DOCTYPE html>
<html>
<head>
    <title>jQuery countdown test</title>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://momentjs.com/downloads/moment.js"></script>
    <script src="http://cdn.rawgit.com/hilios/jQuery.countdown/2.0.4/dist/jquery.countdown.min.js"></script>
</head>

<body>
    <div id="divCountdown">test</div>

    <div id="mydiv">
        this div will be hidden in 10 seconds...
    </div>

    <script>
        $(document).ready(function () {
            var nowPlus30Seconds = moment().add('10', 'seconds').format('YYYY/MM/DD HH:mm:ss');

            $('#divCountdown').countdown(nowPlus30Seconds)
                              .on('update.countdown', function (event) { $(this).html(event.strftime('%D gün %H:%M:%S')); })
                              .on('finish.countdown', function () { $('#mydiv').hide(); });
        });
    </script>
</body>
</html>

答案 1 :(得分:0)

    <script type="text/javascript">
 $('[data-countdown]').each(function() {
   var $this = $(this), finalDate = $(this).data('countdown');
   $this.countdown(finalDate, function(event) {     
   $this.html(event.strftime('%D gün %H:%M:%S'));
   $this.countdown(finalDate)
    .on('update.countdown', function(event) { $this.html(event.strftime('%D gün %H:%M:%S')); })
    .on('finish.countdown', function() { $('#selim').hide(); });
   });
 });
</script>

答案 2 :(得分:0)

你可以使用这个简单的javascript和jquery

<script>
$(document).ready(function () {
var nowPlus30Seconds = moment().add('10', 'seconds').format('YYYY/MM/DD HH:mm:ss');

$('.count1').countdown(nowPlus30Seconds)
.on('update.countdown', function (event) { $(this).html(event.strftime('%Y : %D : %H : %M : %S')); })
.on('finish.countdown', function () { $('#exp_div').hide(); });
});
</script>

完整的代码和演示Here