显示特定时间段的通知栏

时间:2015-08-02 12:21:37

标签: javascript css jsp

此代码将在获取幕帘时间并显示通知栏十分钟后执行。

我想在登录系统中使用此代码。当用户在特定时间登录时,它会显示通知栏。但是如果用户在一定时间后但在十分钟内登录,我想查看通知栏 例如  如果登录时间是一定时间后的两分钟,则会显示8分钟的通知栏。

是否可能以及如何?



(function () {
    function checkTime(i) {
        return (i < 10) ? "0" + i : i;
    }

    function startTime() {
        var today = new Date(),
            h = checkTime(today.getHours()),
            m = checkTime(today.getMinutes()),
            s = checkTime(today.getSeconds());
            // ms = checkTime(today.getMilliseconds());
        document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
         t = setTimeout(function () {
            startTime()
        }, 1000);
    
    if(h==16 && m==52 && s==00 )
                {
             alertify.notify('sample', 'success', 60, function(){  console.log('dismissed'); });
                    }
                    else  if(h==17 && m==01 && s==00 )
                {
             alertify.notify('difficult', 'success', 60, function(){  console.log('dismissed'); });
                    }
                
    }
 
        startTime();   
})();
&#13;
<script src="js/alertify.min.js"></script>
<!-- include the style -->
<link rel="stylesheet" href="css/alertify.min.css" />
<!-- include a theme -->
<link rel="stylesheet" href="css/default.min.css" />
<!-- CSS -->

<!-- CSS -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/alertify.min.css"/>
<!-- Default theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/default.min.css"/>
<!-- Semantic UI theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/semantic.min.css"/>
<!-- Bootstrap theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/bootstrap.min.css"/>

<!-- 
    RTL version
-->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/alertify.rtl.min.css"/>
<!-- Default theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/default.rtl.min.css"/>
<!-- Semantic UI theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/semantic.rtl.min.css"/>
<!-- Bootstrap theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/bootstrap.rtl.min.css"/>
        
&#13;
<div id="time"></div> 
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

简单的数学:

秒钟10分钟= 600;

timeElapsed = currenttime - timeToAlert;
if ((timeElapsed >=0) && (timeElapsed <600)){
//show the alert
timeToShowAlert = 600-timeElapsed;
showAlertForTime(timeToShowAlert);
}