【问题标题】:how to get the current countdwon time in call back in CountDown.js如何在 CountDown.js 的回调中获取当前的倒数计时器
【发布时间】:2017-04-07 03:18:34
【问题描述】:

所以我使用 countDown.js 插件来显示下一个通话时间表。

我想在 endTime 前 5 分钟、2 分钟前和 1 秒前制作 poup。

目前我只能在结束时间前 1 秒显示弹出窗口,我的代码如下。

<script type="text/javascript">
            $(function () {
                var austDay = new Date(<?php echo strtotime(Date::Add($next_scheduled_call->next_call_time))*1000; ?>);
                $('#defaultCountdown').countdown({until: austDay,onExpiry: callDue});
            });

            function  callDue(){
                @if($isSalesManagerGroup ==  'no')
                    alert('Your Call is Get to Due , Please Update Soon.');
                    location.href= "{{ URL::to('/home/leads/history/'.$next_scheduled_call->leads_id.'')}}";
                @endif    
            }
        </script>

如何修改此代码以获得上述要求

【问题讨论】:

    标签: javascript jquery jquery-countdown


    【解决方案1】:

    通过一些Date 函数和setTimeout 的帮助,您可以实现如下:

    <script type="text/javascript">
        $(function () {
            var austDay = new Date(<?php echo strtotime(Date::Add($next_scheduled_call->next_call_time))*1000; ?>);
            var currentDate = new Date(); //current Date
            var diff_in_sec = (austDay.getTime() - currentDate.getTime())/ 1000;
    
            var Seconds_Between_Dates = Math.ceil(diff_in_sec);
    
            var timeBefore5Min = Seconds_Between_Dates - (5 * 60);
            var timeBefore2Min = Seconds_Between_Dates - (2 * 60);
    
            $('#defaultCountdown').countdown({until: austDay,onExpiry: callDue});
    
            setTimeout(function(){
                callDue(); //calling function before 5 min
            },timeBefore5Min * 1000);
    
            setTimeout(function(){
                callDue(); //calling function before 2 min
            },timeBefore2Min * 1000);
        });
    
        function  callDue(){
            @if($isSalesManagerGroup ==  'no')
                alert('Your Call is Get to Due , Please Update Soon.');
                location.href= "{{ URL::to('/home/leads/history/'.$next_scheduled_call->leads_id.'')}}";
            @endif    
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2014-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 2022-11-28
      • 1970-01-01
      相关资源
      最近更新 更多