2014-07-24 2 views
0

이 스크립트를 사용하여 사이트 방문자에게 모달을 표시하지만 하루에 한 번만 표시하는 jquery 쿠키를 성공적으로 설정했습니다.쿠키가있는 모달을 표시하는 시간 초과 기능을 추가하십시오.

<script type="text/javascript"> 
$(document).ready(function(){ 
     // if the cookie doesn't exist create it and show the modal 
     if (! $.cookie('hereToday')) { 

     // create the cookie. Set it to expire in 1 day 
     $.cookie('hereToday', true, { expires: 1 }); 

     //call the reveal modal 
     $('#subscribe').reveal(); 
    } 
}); 
</script> 

어떻게하면 모달을 실행하기 전에 몇 초 지연 될 수있는 스크립트에 타임 아웃 기능을 추가 할 수 있습니까?

답변

1

사용합니다 setTimeout 기능 :

<script type="text/javascript"> 
$(document).ready(function(){ 
     // if the cookie doesn't exist create it and show the modal 
     if (! $.cookie('hereToday')) { 

     // create the cookie. Set it to expire in 1 day 
     $.cookie('hereToday', true, { expires: 1 }); 

     //call the reveal modal 
     var delay=5000; //in ms, this would mean 5 seconds 
     setTimeout(function(){ 
      $('#subscribe').reveal(); 
     },delay); 
    } 
}); 
</script> 
0

그냥 setTimeout을 사용하십시오.

setTimeout(function() { 
    $('#subscribe').reveal(); 
},5000); 

모달은 5 초 후에 호출됩니다.