Witam,
mam na stronie dwa skrypty, odliczający czas:

[JAVASCRIPT] pobierz, plaintext
  1. var javascript_countdown = function () {
  2. var time_left = 10;
  3. var output_element_id = 'javascript_countdown_time';
  4. var keep_counting = 1;
  5.  
  6.  
  7. function countdown() {
  8. if(time_left < 2) {
  9. keep_counting = 0;
  10. }
  11.  
  12. time_left = time_left - 1;
  13. }
  14.  
  15. function add_leading_zero(n) {
  16. if(n.toString().length < 2) {
  17. return '0' + n;
  18. } else {
  19. return n;
  20. }
  21. }
  22.  
  23. function format_output() {
  24. var hours, minutes, seconds;
  25. seconds = time_left % 60;
  26. minutes = Math.floor(time_left / 60) % 60;
  27. hours = Math.floor(time_left / 3600);
  28.  
  29. seconds = add_leading_zero( seconds );
  30. minutes = add_leading_zero( minutes );
  31. hours = add_leading_zero( hours );
  32.  
  33. return hours + ':' + minutes + ':' + seconds;
  34. }
  35.  
  36. function show_time_left() {
  37. document.getElementById(output_element_id).innerHTML = format_output();//time_left;
  38. }
  39.  
  40. function no_time_left() {
  41. document.getElementById(output_element_id).innerHTML = no_time_left_message;
  42. }
  43.  
  44. return {
  45. count: function () {
  46. countdown();
  47. show_time_left();
  48. },
  49. timer: function () {
  50. javascript_countdown.count();
  51.  
  52. if(keep_counting) {
  53. setTimeout("javascript_countdown.timer();", 1000);
  54. } else {
  55. no_time_left();
  56. }
  57. },
  58. setTimeLeft: function (t) {
  59. time_left = t;
  60. if(keep_counting == 0) {
  61. javascript_countdown.timer();
  62. }
  63. },
  64. init: function (t, element_id) {
  65. time_left = t;
  66. output_element_id = element_id;
  67. javascript_countdown.timer();
  68. }
  69. };
  70. }();
  71.  
  72. javascript_countdown.init(1200, 'javascript_countdown_time');
[JAVASCRIPT] pobierz, plaintext

i pasek postępu:

[JAVASCRIPT] pobierz, plaintext
  1. function zxcAnimate(mde,obj,srt){
  2. this.to=null;
  3. this.obj=typeof(obj)=='object'?obj:document.getElementById(obj);
  4. this.mde=mde.replace(/\W/g,'');
  5. this.data=[srt||0];
  6. return this;
  7. }
  8.  
  9. zxcAnimate.prototype.animate=function(srt,fin,ms,scale,c){
  10. clearTimeout(this.to);
  11. this.time=ms||this.time||0;
  12. this.neg=srt<0||fin<0;
  13. this.data=[srt,srt,fin];
  14. this.mS=this.time*(!scale?1:Math.abs((fin-srt)/(scale[1]-scale[0])));
  15. this.c=typeof(c)=='string'?c.charAt(0).toLowerCase():this.c?this.c:'';
  16. this.inc=Math.PI/(2*this.mS);
  17. this.srttime=new Date().getTime();
  18. this.cng();
  19. }
  20.  
  21. zxcAnimate.prototype.cng=function(){
  22. var oop=this,ms=new Date().getTime()-this.srttime;
  23. this.data[0]=(this.c=='s')?(this.data[2]-this.data[1])*Math.sin(this.inc*ms)+this.data[1]:(this.c=='c')?this.data[2]-(this.data[2]-this.data[1])*Math.cos(this.inc*ms):(this.data[2]-this.data[1])/this.mS*ms+this.data[1];
  24. this.apply();
  25. if (ms<this.mS) this.to=setTimeout(function(){oop.cng()},10);
  26. else {
  27. this.data[0]=this.data[2];
  28. this.apply();
  29. if (this.Complete) this.Complete(this);
  30. }
  31. }
  32.  
  33. zxcAnimate.prototype.apply=function(){
  34. if (isFinite(this.data[0])){
  35. if (this.data[0]<0&&!this.neg) this.data[0]=0;
  36. if (this.mde!='opacity') this.obj.style[this.mde]=Math.floor(this.data[0])+'px';
  37. else zxcOpacity(this.obj,this.data[0]);
  38. }
  39. }
  40.  
  41. function zxcOpacity(obj,opc){
  42. if (opc<0||opc>100) return;
  43. obj.style.filter='alpha(opacity='+opc+')';
  44. obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=opc/100-.001;
  45. }
[JAVASCRIPT] pobierz, plaintext


[JAVASCRIPT] pobierz, plaintext
  1. function Bar(o){
  2. var obj=document.getElementById(o.ID);
  3. this.oop=new zxcAnimate('width',obj,0);
  4. this.max=obj.parentNode.offsetWidth;
  5. this.to=null;
  6. }
  7.  
  8. Bar.prototype={
  9.  
  10. Start:function(sec){
  11. clearTimeout(this.to);
  12. this.oop.animate(0,this.max,sec*1000);
  13. this.srt=new Date();
  14. this.sec=sec;
  15. this.Time();
  16. },
  17.  
  18. Time:function(sec){
  19. var oop=this,sec=this.sec-Math.floor((new Date()-this.srt)/1000);
  20.  
  21. if (sec>0){
  22. this.to=setTimeout(function(){ oop.Time(); },1000);
  23. }
  24. }
  25.  
  26. }
  27.  
  28. var B1=new Bar({
  29. ID:'bar'
  30. });
  31.  
  32. B1.Start(1200);
[JAVASCRIPT] pobierz, plaintext


Obydwa skrypty odliczają 20 min. Problem pojawia się w Operze - pasek postępu kończy 11 sekund za wcześnie lub licznik za wolno (?). W innych przeglądarkach są zsynchronizowane. Jeżeli istnieje jakieś rozwiązanie tego problemu, to byłbym bardzo wdzięczny za każdą wskazówkę.

//edit
Problem rozwiązany.