Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/05/2013, 11:03
Avatar de alberto510a
alberto510a
 
Fecha de Ingreso: abril-2013
Mensajes: 351
Antigüedad: 11 años
Puntos: 35
Respuesta: Repetir conjunto de funciones cada X segundos

Hola.

Imaginemos que tienes esto:

Código Javascript:
Ver original
  1. $( "#slide01" ).animate( { width: "700px" }, { queue: false, duration: 800 })
  2.               $( "#slide02" ).animate( { width: "30px" }, { queue: false, duration: 800 })
  3.               $( "#slide03" ).animate( { width: "20px" }, { queue: false, duration: 800 })
  4.               $( "#slide04" ).animate( { width: "150px" }, { queue: false, duration: 800 })

Para que eso fuera una función tan solo tendríamos que ponerlo entre function():

Código Javascript:
Ver original
  1. function slidelink01(){
  2.  
  3.               $( "#slide01" ).animate( { width: "700px" }, { queue: false, duration: 800 })
  4.               $( "#slide02" ).animate( { width: "30px" }, { queue: false, duration: 800 })
  5.               $( "#slide03" ).animate( { width: "20px" }, { queue: false, duration: 800 })
  6.               $( "#slide04" ).animate( { width: "150px" }, { queue: false, duration: 800 })
  7.            
  8. }

Bien, ahora hay 2 posibilidades setTimeOut (1 vez) setInterval (cada x tiempo) supongo que a ti te interesa más la segunda y que además comience a suceder tras la carga de la página:

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.  
  3. function slidelink01(){
  4.               $( "#slide01" ).animate( { width: "700px" }, { queue: false, duration: 800 })
  5.               $( "#slide02" ).animate( { width: "30px" }, { queue: false, duration: 800 })
  6.               $( "#slide03" ).animate( { width: "20px" }, { queue: false, duration: 800 })
  7.               $( "#slide04" ).animate( { width: "150px" }, { queue: false, duration: 800 })          
  8. }
  9.  
  10. window.setInterval(slidelink01(),1000);
  11.  
  12. });

De esta forma hacemos que cuando cargue el documento se cree una función y que cada 1000 milisegundos (1 segundo) suceda esta misma.

Saludos.