Javascript 根据条件自动打开模式

Javascript 根据条件自动打开模式,javascript,html,jquery,twitter-bootstrap,Javascript,Html,Jquery,Twitter Bootstrap,我已经集成了一个默认模式materialize,但是我想将一个开放条件集成到我的模式中。我的应用程序中有一个倒计时,当这个倒计时到达xx分钟时,我必须自动显示我的模式。谢谢 我从materialize上的Modal中获取了这个简单模型 <!-- Modal Trigger --> <a class="waves-effect waves-light btn modal-trigger" href="#modal1">Moda

我已经集成了一个默认模式materialize,但是我想将一个开放条件集成到我的模式中。我的应用程序中有一个倒计时,当这个倒计时到达xx分钟时,我必须自动显示我的模式。谢谢

我从materialize上的Modal中获取了这个简单模型

  <!-- Modal Trigger -->
  <a class="waves-effect waves-light btn modal-trigger" href="#modal1">Modal</a>

  <!-- Modal Structure -->
  <div id="modal1" class="modal">
    <div class="modal-content">
      <h4>Modal Header</h4>
      <p>A bunch of text</p>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
    </div>
  </div>

模态头
一串文字

我的倒计时基于此模型:

<script type="text/javascript">
        countdownManager = {
            // Configuration
            targetTime: new Date('July 24 10:40:00 2020'), // Target date of the counter. Please fill in the end date and time completely
            displayElement: { 
                hour: null,
                min:  null,
                sec:  null
            },
            // Initialization of the countdown (to be called 1 time when the page loads)
            init: function(){
               
                this.displayElement.hour = jQuery('#countdown_hour');
                this.displayElement.min  = jQuery('#countdown_min');
                this.displayElement.sec  = jQuery('#countdown_sec');
                // Launch of the countdown
                this.tick(); // 
                window.setInterval("countdownManager.tick();", 1000); // Next ticks, repeated every second (1000 ms)
            },
            // Updates the countdown (clock tick)
            tick: function(){
                // Present time
                var timeNow  = new Date();
                console.log(timeNow);
                // We make sure that the remaining time is never negative (which is the case in the future of targetTime)
                if( timeNow > this.targetTime ){
                    timeNow = this.targetTime;
                }
                // Calculation of remaining time
                var diff = this.dateDiff(timeNow, this.targetTime);
                // this.displayElement.day.text(  diff.day  );
                this.displayElement.hour.text( diff.hour );
                this.displayElement.min.text(  diff.min  );
                this.displayElement.sec.text(  diff.sec  );
            },
            // Calculate the difference between 2 dates, in day / hour / minute / second
            dateDiff: function(date1, date2){
                var diff = {}                           
                var tmp = date2 - date1;
                tmp = Math.floor(tmp/1000);             
                diff.sec = tmp % 60;                    
                tmp = Math.floor((tmp-diff.sec)/60);    
                diff.min = tmp % 60;                    
                tmp = Math.floor((tmp-diff.min)/60);    
                diff.hour = tmp % 24;                   
                return diff;
            }
        };
        jQuery(function($){
            // Launch of the countdown when loading the page on the server side
            countdownManager.init();
        });
    </script>

倒计时管理器={
//配置
targetTime:新日期('July 24 10:40:00 2020'),//计数器的目标日期。请完整填写结束日期和时间
displayElement:{
小时:空,
min:null,
秒:空
},
//倒计时初始化(页面加载时调用1次)
init:function(){
this.displayElement.hour=jQuery(“#倒计时_hour”);
this.displayElement.min=jQuery('#countdown_min');
this.displayElement.sec=jQuery(“#倒计时_sec”);
//启动倒计时
this.tick();//
setInterval(“countdownManager.tick();”,1000);//下一个ticks,每秒重复一次(1000毫秒)
},
//更新倒计时(时钟滴答声)
勾选:函数(){
//现在
var timeNow=新日期();
console.log(timeNow);
//我们确保剩余时间永远不会为负(targetTime的未来就是这样)
如果(timeNow>this.targetTime){
timeNow=this.targetTime;
}
//剩余时间的计算
var diff=this.dateDiff(timeNow,this.targetTime);
//this.displayElement.day.text(diff.day);
this.displayElement.hour.text(差异小时);
this.displayElement.min.text(diff.min);
此.displayElement.sec.文本(diff.sec);
},
//计算两个日期之间的差异,以天/小时/分钟/秒为单位
dateDiff:函数(date1、date2){
var diff={}
var tmp=date2-date1;
tmp=数学楼层(tmp/1000);
差秒=tmp%60;
tmp=数学层((tmp-diff.sec)/60);
差异最小值=tmp%60;
tmp=数学楼层((tmp-diff.min)/60);
差异小时=tmp%24;
返回差;
}
};
jQuery(函数($){
//在服务器端加载页面时启动倒计时
countdownManager.init();
});

使用
打开
方法打开任何模式:

$('#modal1').modal('open');

使用
打开
方法打开任何模式:

$('#modal1').modal('open');

使用
$('#modal1')。模态('show')
打开不正确的模态,没有方法
'show'
使用
$('#modal1')。模态('show')
打开不正确的模态,没有方法
'show'