Ver Mensaje Individual
  #9 (permalink)  
Antiguo 04/05/2013, 18:08
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 655
Antigüedad: 21 años, 10 meses
Puntos: 6
Respuesta: Alternar Color en DIV

Ahora sale esto

Código PHP:
Current color: #ff00ff
Current color: #000000
Current color: #abc5e2
Current color: 
Current color: #ffffff
Current color: #ff00ff
Current color: #000000
Current color: #abc5e2
Current color: 
Current color: #ffffff
Current color: #ff00ff 
esta ahora si.
Código PHP:
<?php
class TableColorManager
{
    private 
$_colors = array();
    private 
$_currentColor  = 0;

    public function 
AddColor($color)
    {
        if(!
is_string($color))
        {
            throw new 
Exception("\$color parameter must be a string");
        }

        if(
preg_match('/^#[a-f0-9]{6}$/i', $color)) 
        {
            
array_push($this->_colors, $color);
        }
        else
        {
            throw new 
Exception("Invalid color");
        }
    
        return 
$this;
    }

    public function 
getNextColor()
    {
        if(
$this->_currentColor > count($this->_colors) - 1)
        {
            
$this->_currentColor = 0;
        }
        else
        {
            
$this->_currentColor++;
        }

        return 
$this->_colors[$this->_currentColor];
    }
}

$colors = new TableColorManager();
$colors->AddColor("#ffffff")->AddColor("#ff00ff");
$colors->AddColor("#000000");
$colors->AddColor("#abc5e2");

for(
$i = 0; $i <= 10; $i++)
{
    echo 
"Current color: " . $colors->getNextColor() . "<br />";
}
?>
Cita:
Iniciado por bulter Ver Mensaje
No uses hex cortos usa el el color entero es decir #fff esto no pon #ffffff no uses #000 usa #000000 etc.