Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/06/2011, 01:11
InKarC
 
Fecha de Ingreso: noviembre-2005
Mensajes: 426
Antigüedad: 18 años, 5 meses
Puntos: 87
Respuesta: barra de tiempo javascript¿?

Código Javascript:
Ver original
  1. function reproductor(){
  2.     this.tiempo = "01:15",
  3.     this.barra = document.getElementById("barra")
  4.     this.ir = function(event){ this.segundoActual = (this.segundos / barra.style.width.replace("px","")) * event.offsetX; this.pausado = false; document.getElementById("pausar").innerHTML = "Pausar"  }
  5.     this.navegacion = document.getElementById("navegacion")
  6.     this.time = document.getElementById("time")
  7.     this.segundos =  Number(this.tiempo.split(":")[0] * 60) + Number(this.tiempo.split(":")[1])
  8.     this.pasos = barra.style.width.replace("px","") / this.segundos
  9.     this.segundoActual = 0;
  10.     this.pausado = false;
  11.     this.animacion = setInterval(function(){
  12.         if(!reproductor.pausado){
  13.         reproductor.navegacion.style.left = (Math.round((reproductor.pasos ) * reproductor.segundoActual)) + "px";
  14.         reproductor.segundoActual += 0.03125;
  15.         reproductor.final = reproductor.barra.style.width.replace("px","") - reproductor.navegacion.style.width.replace("px","");
  16.         reproductor._minutos = Math.floor(Math.round(reproductor.segundoActual)/60)
  17.         reproductor._segundos =  Math.round(reproductor.segundoActual) - (reproductor._minutos*60)
  18.         if(String(reproductor._minutos).length < 2){
  19.             reproductor._minutos = String("0") + String(reproductor._minutos)          
  20.         }
  21.         if(String(reproductor._segundos).length < 2){
  22.             reproductor._segundos = String("0")+ String(reproductor._segundos)         
  23.         }
  24.         reproductor.time.innerHTML = reproductor._minutos + ":" + reproductor._segundos
  25.         if(reproductor.segundoActual >= reproductor.segundos || reproductor.navegacion.style.left.replace("px","") > reproductor.final ){
  26.                
  27.             reproductor.navegacion.style.left = reproductor.final  + "px"
  28.             reproductor.time.innerHTML = reproductor.tiempo;
  29.             reproductor.pausado = true;
  30.             document.getElementById("pausar").innerHTML = "Pausar"
  31.         }      
  32.         }
  33.        
  34.     }, 31.25)
  35. }
  36.  
  37. var reproductor = new reproductor()

Que suerte tiene de que yo sea un desocupado.

Version en jsfiddle

Lo mas increible es que funciona hasta en Internet Explorer 6, lol