javascript - Have an button reset and start a countdown timer -


i trying begin countdown timer when button clicked. have searched , found few different items, nothing seems function.

i have different buttons throughout domain set different times (ie: 120 seconds, 60 seconds, etc). display in same spot on every page ( div in top right of loaded page ) wanting use external js scripts/timer.js

i can use <div id="timer"></div> place timer.

my questions: how call function start timer. suggested script said timer when amount of time can change , has carry on pages (i've been using $_session['x']to pass information between .php

<div class="headertopgab">     <div style="float: left; margin-left: 20px">         galactic credits:          <?php echo "&ccedil;".$_session['galacticcredits']; ?>     </div>     <div style="margin-left: 50px; float: left">         <?php echo "".$_session['currentlocation']; ?>     </div>     <div style="float:right">         <div id="time">10</div>  <!-- want countdown-->     </div> </div> 

you can use

var countdown; var counter = function(){     var time = parseint($('#time').text());     if (time !== 0){         $('#time').text(time - 1);     }else{         clearinterval(countdown);     } } countdown = setinterval(counter , 1000); 

demo


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -