i developing website bids , using countdown timer , if have format date countdown works correctly
$this.html(event.strftime('%d días %h:%m:%s')); i have number in database , examples : 120seconds
how can change format seconds ? if put %s , countdown doesn't work.
<script src="{{ url::asset('js/jquery.countdown.js') }}" type="text/javascript"></script> <script src="{{ url::asset('js/jquery.countdown.min') }}" type="text/javascript"></script> <script type="text/javascript"> $('[data-countdown]').each(function() { var $this = $(this), finaldate = $(this).data('countdown'); $this.countdown(finaldate, function(event) { $this.html(event.strftime('%d días %h:%m:%s')); }); }); </script> updated2
the code works correctly can show 1 timer because idand need use .class.
i change document.getelementbyid document.getelementbyclassname , doesn't work.
<script type="text/javascript"> function datetohhmmss(date) { var hours = date.gethours() - 1; var minutes = date.getminutes(); var seconds = date.getseconds(); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; } function countdown(count) { var start = new date(); var end = new date(start.gettime() + (count * 1e3)); // * 1e3 milliseconds var intervalhandle = setinterval(function() { var current = new date(); var delta = new date(end.gettime() - current.gettime()); $(".countdown").text(datetohhmmss(delta)); if(delta.gettime() <= 0) { clearinterval(intervalhandle); $(".countdown").text(datetohhmmss(delta)); } }, 1e3); } $('[data-countdown]').each(function() { var id = $(this).attr('data-countdown'); countdown(id); }); </script> updated3
hello time , when show console.log(id) can see of numbers recieve , when use countdown(id) send last id.
$('[data-countdown]').each(function() { var id = $(this).attr('data-countdown'); var export_data = []; export_data.push(id); $.each(export_data, function( index, value ) { countdown(value); }); });
this should trick :
function datetohhmmss(date) { var hours = date.gethours() - 1; var minutes = date.getminutes(); var seconds = date.getseconds(); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; } function countdown(count) { var start = new date(); var end = new date(start.gettime() + (count * 1e3)); // * 1e3 milliseconds var updatecountdown = function() { var current = new date(); var delta = new date(end.gettime() - current.gettime()); document.getelementbyid('countdown').innerhtml = datetohhmmss(delta); if(delta.gettime() <= 0) { clearinterval(intervalhandle); document.getelementbyid('countdown').innerhtml = "time over"; } }; updatecountdown(); //otherwise first second not visible var intervalhandle = setinterval(updatecountdown, 1e3); } countdown(120); //120 or whatever value want long in second <div id="countdown"></div>
Comments
Post a Comment