Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/07/2010, 03:49
markmb
 
Fecha de Ingreso: octubre-2009
Ubicación: En el ordenador
Mensajes: 504
Antigüedad: 14 años, 7 meses
Puntos: 10
Respuesta: Trabajo con imágenes

Y he aquí la respuesta:

Código HTML:
for (i=0;i<document.images.length;i++){
    if (document.images[i].border != 0){
        document.images[i].border = 0;
    }
}
document.images['foto' + id].border=2;
Este sería todo el código entero:

Código PHP:
<div id="contimg">
<?php
$resto 
'';
echo (
'<script language="javascript">'."\n");
echo (
'var id=1;'."\n");
for (
$i 1$i<=count($img); $i++){
    echo (
'imagen'.$i.'=new Image'."\n");
    echo (
'imagen'.$i.'.src="imgs/'.$img[$i-1].'"'."\n");
    if (
$i == 1){
        
$resto .= 'if (id == 1){
            document.images["fotog"].src=imagen1.src'
."\n";
    }else if (
$i == count($img)){
        
$resto .= '}else{
            document.images["fotog"].src=imagen'
;
        
$resto .= $i;
        
$resto .= '.src;
            }'
."\n";
    }else{
        
$resto .= '}else if (id == ';
        
$resto .= $i;
        
$resto .= '){
            document.images["fotog"].src=imagen'
;
        
$resto .= $i;
        
$resto .= '.src';
        
$resto .= "\n";
    }
}
echo (
'function cambiar(id) {'."\n");
echo 
$resto."\n";
echo 
'for (i=0;i<document.images.length;i++){
    if (document.images[i].border != 0){
        document.images[i].border = 0;
    }
}'
."\n";
echo 
"document.images['foto' + id].border=2;"."\n";
echo 
'}'."\n";
echo (
'</script>');
?>
<div id="imgg">
<img src="imgs/<?php echo $img[0]; ?>" title="Imagen" name="fotog" alt="Imagen principal" />
</div>
<div id="thumbs">
<?php
$i 
1;
foreach (
$img as $path){
    echo (
'<img src="thmbs/'.$path.'" title="Imagen" alt="Imagen secundaria" name="foto'.$i.'" onMousedown="cambiar('.$i.') "');
    if (
$i == 1){
        echo (
'border=2');
    }
    echo (
'/>');
    
$i++;
}
?></div>
</div>
($img es un array con las rutas a las fotos)