0

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

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

现在我只能在 End Time 前 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>

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

4

1 回答 1

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>
于 2016-11-23T08:22:29.923 回答