【问题标题】:Hide a div container based on timestamp根据时间戳隐藏 div 容器
【发布时间】:2014-04-08 14:46:30
【问题描述】:

我想在创建一段内容后在页面上显示警告横幅 (div) 30 分钟。 30 分钟后,横幅不应再显示。这是为了让用户知道视频需要时间到transcode,因此在此之前可能无法使用。

想法:

var timeStamp = format_date(var node.created, 'custom', 'M j, Y g:i A');
var currentTime = new Date();

if {
    currenTime < timeStamp + (30_minutes) = document.getElementById(alert_banner).style.display = 'block';
}
else {
    currentTime > timeStamp + (30_minutes) = document.getElementById(alert_banner).style.display = 'none';
}

【问题讨论】:

    标签: javascript html drupal-7 timestamp show-hide


    【解决方案1】:

    你可以试试

    var time = 1000 * 60 * 30 //milisecond * second * minute
    setTimeout(function(){
        // Your function here e.i
        document.getElementById(alert_banner).style.display = 'none';
    }, time)
    

    【讨论】:

      【解决方案2】:

      正如 headlikearock 所说,时间间隔可能是你最好的选择:

      setInterval(function(){document.getElementById(alert_banner).style.display = 'none';},1800000);
      

      将其放置在加载的 JS 代码中,它应该在该语句运行 30 秒后触发内联定义的 JS 函数。

      Here 是 5 秒后 div 消失的示例。

      【讨论】:

        【解决方案3】:

        您可以使用 setTimeout 方法(http://www.w3schools.com/js/js_timing.asp)在 30 分钟后隐藏 div。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-30
          • 2013-03-21
          • 1970-01-01
          • 1970-01-01
          • 2011-01-15
          • 1970-01-01
          • 2015-08-07
          • 1970-01-01
          相关资源
          最近更新 更多