Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I create A 5 second Countdown timer with jquery that ends with a login popup?

Tags:

jquery

How would i create a jquery timer that starts when a link is 'mouse-overed', Displays a 1,2,3, 4 and 5, one after the other. Then on 5 pops up a login box?

Cheers.

like image 629
Tapha Avatar asked Jun 22 '10 00:06

Tapha


People also ask

What is countdown function on timer?

What is a countdown timer. A countdown timer is a virtual clock running on a landing page. And it counts down from a certain date to indicate the beginning (or the end) of an event. On eCommerce websites, you can use a countdown timer to display the beginning (or the end) of an offer.


3 Answers

How about:

var counter = 0;
var interval = setInterval(function() {
    counter++;
    // Display 'counter' wherever you want to display it.
    if (counter == 5) {
        // Display a login box
        clearInterval(interval);
    }
}, 1000);
like image 127
VoteyDisciple Avatar answered Oct 17 '22 17:10

VoteyDisciple


This is exactly the code that worked for me:

<p>You'll be automatically redirected in <span id="count">10</span> seconds...</p>

<script type="text/javascript">

window.onload = function(){

(function(){
  var counter = 10;

  setInterval(function() {
    counter--;
    if (counter >= 0) {
      span = document.getElementById("count");
      span.innerHTML = counter;
    }
    // Display 'counter' wherever you want to display it.
    if (counter === 0) {
    //    alert('this is where it happens');
        clearInterval(counter);
    }

  }, 1000);

})();

}

</script>

<meta http-equiv="refresh" content="10;url=http://www.example.com" />

Hope it helps ;)

like image 23
Ifti Mahmud Avatar answered Oct 17 '22 17:10

Ifti Mahmud


http://jsfiddle.net/brynner/Lhm1ydvs/

HTML

<span class="c" id="5"></span>

JS

function c(){
    var n=$('.c').attr('id');
    var c=n;
    $('.c').text(c);
    setInterval(function(){
        c--;
        if(c>=0){
            $('.c').text(c);
        }
        if(c==0){
            $('.c').text(n);
        }
    },1000);
}

// Start
c();

// Loop
setInterval(function(){
    c();
},5000);
like image 15
Brynner Ferreira Avatar answered Oct 17 '22 17:10

Brynner Ferreira