Ver Mensaje Individual
  #22 (permalink)  
Antiguo 05/05/2013, 12:50
Avatar de bulter
bulter
 
Fecha de Ingreso: enero-2008
Mensajes: 137
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Alternar Color en DIV

Código PHP:
<?php 
class TableColorManager   
{   
    private 
$_colors = array();   
    private 
$_currentColor  0;   

    public function 
Add($color)   
    {   
        if(!
is_string($color) && !is_array($color))   
        {   
            throw new 
Exception("\$color parameter must be a string or array");   
        }   

        if(
is_string($color)) 
        { 
            
$this->AddColor($color); 
        } 
        else if(
is_array($color)) 
        { 
            foreach(
$color as $colorValue
            { 
                
$this->AddColor($colorValue); 
            } 
        } 
       
        return 
$this;   
    }   

    private function 
AddColor($color
    { 
        if(
preg_match('/^#[a-f0-9]{6}$/i'$color))    
        {   
            
array_push($this->_colors$color);   
        }   
        else   
        {   
            throw new 
Exception("Invalid color");   
        }   
    } 
     
    public function 
Next()   
    {   
        if(
$this->_currentColor >= count($this->_colors) - 1)   
        {   
            
$this->_currentColor 0;   
        }   
        else   
        {   
            
$this->_currentColor++;   
        }   
         
        return 
$this->_colors[$this->_currentColor];   
    }   
     
    public function 
Current() 
    { 
        return 
$this->_colors[$this->_currentColor]; 
    } 
     
    public function 
Prev() 
    { 
        
$returnIndex = ($this->_currentColor min(2count($this->_colors)-1));  
         
        if(
$returnIndex 0
        { 
            
$returnIndex count($this->_currentColor) + 1
        } 
     
        return 
$this->_colors[$returnIndex]; 
    } 
}   

$colors = new TableColorManager();   
$colors->Add(array("#006699""#ff00ff")); 
$colors->Add("#abc5e2"); 

for(
$i 0$i 8$i++) 

    echo 
"<table style='width: 200px; height: 100px; border: 1px solid #000; text-align: center; display: inline-block;'> 
            <tr> 
                <td style='background-color: " 
$colors->Next() . "; height: 10px;'> 
                    Nombre 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    FOTO 
                </td> 
            </tr> 
        </table>&nbsp;&nbsp;&nbsp;&nbsp;"



?>
Aqui lo tienes...

Saludos