MyBB Community Forums

Full Version: Twitter Bootstrap and JS countdown?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Does anybody know how to make a button using twitter's bootstrap CSS framework that counts down?

Twitter bootstrap has button that can be enabled or disabled using JavaScript. Basically I want it to load te page in a disabled state, count down for ten seconds and then activate to provide the link for a few files I want to host Smile


Thanks
Could you not have text that count downs with the same styling as a button and then after the countdown replace it with a real button?
Possibly, but my JavaScript is terrible Toungue
Well it's going to be javascript no matter how you try to do it Toungue. In less you have a countdown that redirects to another page with the real button.
Something like this aught to suffice:

var timeToWait = 30; // wait 30 seconds

var countDown = setInterval(countDownTimer, 1000); // run our function every second

function countDownTimer()
{
	timeToWait = timeToWait-1; // count timer down by one

  	if (timeToWait <= 0) // if timer is finished, stop counting down and change our download button
	{
		clearInterval(countDown);
		$('#downloadButton').html('Download Now!').attr('href', 'downloadNow.jpg'); // change this to do whatever you want the button to do...
		return;
	}

	$('#downloadButton').html(timeToWait + ' seconds to wait...'); // display the countdown time left
}

Obviously you'll wish to change it to perform as you want. I haven't tested it either but it might do what you want Toungue
So what would I put for the button? Toungue
Whatever you want, just use a link with the ID of downloadButton and a blank href attribute if you want.
Ok, so the ID needs to be "downloadButton" Smile I wasn't sure

Also, I assume I can put another attribute on? Like the class? Using:

.attr('class','class2')
Yup, it should work just fine Smile
(2012-08-12, 07:38 AM)Tom K. Wrote: [ -> ]Also, I assume I can put another attribute on? Like the class? Using:

.attr('class','class2')

You can also use .addClass() if you would prefer that. Either work though.
Pages: 1 2