Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/09/2010, 13:56
Avatar de maxi_lance
maxi_lance
 
Fecha de Ingreso: julio-2006
Ubicación: Capital Federal
Mensajes: 220
Antigüedad: 17 años, 9 meses
Puntos: 2
Mostrar <li> por orden en lugar de random

Que tal, adapte un script de la web que funciona OK. Muestra el contenido de los <li> que haya cargado de a uno por vez por un lapso de tiempo determinado. Todo esto lo hace aleotoriamente, es decir, con random.

Lo que necesito es que las muestre segun un orden, del menor al mayor por ejemplo. COmo podria editar el script para incorporarle numeros a los divs y que la funcion js lo interprete ?

El ejemplo lleva includio el jquery.js.

Código HTML:
<ul id="tips">
	<li>... if you want to become a better coder you need to eat your vegetables?</li>
	<li>... it takes more time to code a web page then to make a pizza?</li>
	<li>... you should validate your code?</li>
	<li>... jQuery is your friend? For real!</li>
	<li>... no matter what some people claim, you can't learn CSS in 3 hours?</li>
</ul> 
Código HTML:
#tips, #tips li{
	margin:0;
	padding:0;
	list-style:none;
	}
#tips{
	width:250px;
	font-size:16px;
	line-height:120%;
	}
#tips li{
	padding:20px;
	background:#e1e1e1;
	display:none; /* hide the items at first only */
	}
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.  
  3. this.randomtip = function(){
  4.  
  5.     var pause = 3000; // define the pause for each tip (in milliseconds)
  6.     var length = $("#tips li").length;
  7.     var temp = -1;     
  8.  
  9.     this.getRan = function(){
  10.         // get the random number
  11.         var ran = Math.floor(Math.random()*length) + 1;
  12.         return ran;
  13.     };
  14.     this.show = function(){
  15.         var ran = getRan();
  16.         // to avoid repeating
  17.         while (ran == temp){
  18.             ran = getRan();
  19.         };
  20.         temp = ran;
  21.         $("#tips li").hide();  
  22.         $("#tips li:nth-child(" + ran + ")").fadeIn("fast");       
  23.     };
  24.    
  25.     show(); setInterval(show,pause);
  26.    
  27. };
  28.  
  29. $(document).ready(function(){  
  30.     randomtip();
  31. });
  32.  
  33. </script>