jquery - JavaScript Timer Based Popup -


trying make simple timer based popup. once timer reach 10 second popup visible. timer should pause or stop, after clicking on 'ok' button of popup, timer should restart 0. please help

https://jsfiddle.net/ckf0g9qj/5/

var span = document.queryselector("#time"); countdown(0);  function countdown(counter) {   var interval = setinterval(function() {     var minutes = ((counter / 60) | 0) + "";     var seconds = (counter % 60) + "";     var format = "" +       new array(3 - minutes.length).join("0") + minutes + ':' + new array(3 - seconds.length).join("0") + seconds;     span.innerhtml = format;     counter++;      if (seconds == 10) {       // $("#timemodal").modal(); bs model box open       // countdown(0);       document.getelementbyid("popup").style.visibility = "visible";     }   }, 1e3) }  function timerreset() {   countdown(0);   alert("ok");   document.getelementbyid("popup").style.visibility = "hidden"; } 

use clearinterval when reach seconds == 10 condition

i think looking for:

#popup {    width:200px;   height:200px;  border:solid 1px red;   visibility:hidden;  }    <!-- begin snippet: js hide: false console: true babel: false -->
<div id="time"></div>  <div id="popup">    <button id="ok" onclick="timerreset()">  ok  </button>  </div>    <script>    var span = document.queryselector("#time");    countdown(0);      function countdown(counter) {        var interval = setinterval(function() {        var minutes = ((counter / 60) | 0) + "";        var seconds = (counter % 60) + "";        var format = "" +          new array(3 - minutes.length).join("0") + minutes +          ':' +          new array(3 - seconds.length).join("0") + seconds;          span.innerhtml = format;        counter++;        if (seconds == 10) {          clearinterval(interval);          // $("#timemodal").modal(); bs model box open          // countdown(0);          document.getelementbyid("popup").style.visibility = "visible";        }      }, 1e3)    }      function timerreset() {      countdown(0);      alert("ok");      document.getelementbyid("popup").style.visibility = "hidden";    }  </script>


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -