Colorbox弹出按计划

时间:2014-09-29 04:02:33

标签: colorbox

我查看并尝试使用我在网上找到的脚本来设置预定的彩盒,到目前为止它只适用于Chrome。下面是我现在正在使用的脚本。我知道这一定是非常基本的,但我希望有人可以帮助或指出正确的方向。

更新

我想要的是每次人们访问时都会显示一个颜色框,颜色框会在通过“ScheduleDate”时禁用它的功能,现在只有chrome会按计划显示颜色框,即firefox和safari似乎没有认识到剧本。浏览器控制台没有错误。

<script>
    today = new Date();
    today_year = today.getFullYear(); 
    today_month = today.getMonth()+1; 
    today_date = today.getDate(); 
    today_hours = today.getHours(); 
    today_minutes = today.getMinutes(); 
    today_seconds = today.getSeconds(); 

    var CurrentDate = today_year+"-"+today_month+"-"+today_date+"  "+today_hours+":"+today_minutes+":"+today_seconds;
    var ScheduleDate = "2014-10-12 00:00:00";

    if (  (Date.parse(CurrentDate)).valueOf() <= (Date.parse(ScheduleDate)).valueOf())
    {
        $(document).ready(function(){               
            $(".iframe").colorbox({iframe:true, width:"300px", height:"250px", open:true});             
        });                     
    }
</script>

1 个答案:

答案 0 :(得分:0)

要使代码在FireFox中运行,我需要做两件事:

  1. 将所有javascript代码包裹在$(document).ready()
  2. 更改CurrentDate的构建和比较方式。
  3. 运行下面的堆栈代码或参考此jsfiddle。另外,我从他们的一个examples中获取了CSS。

    // javascript
    $(document).ready(function() {
      var currentDate = new Date();
      var scheduleDate = new Date(2014, 9, 12, 0, 0, 0);
    
      if (currentDate <= scheduleDate) {
        $.colorbox({
          iframe: true,
          innerWidth: "300px",
          innerHeight: "300px",
          open: true
        });
      }
    });
    <!-- HTML -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/example1/colorbox.css" rel="stylesheet"/>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/jquery.colorbox-min.js"></script>