如何在CountDown.js中回调当前countdwon时间

时间:2016-11-23 08:04:07

标签: javascript jquery jquery-countdown

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

我想在结束前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>

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

1 个答案:

答案 0 :(得分:0)

使用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>