how to make the photo gallery show a photo before clicking on it?

0

Hello, I have a code from a photo gallery but it shows only a white background when you open the page, only the photo will appear when you click on any .. I would like you to open a page with a photo in the gallery before you need to click on some. Here is the code:

<div class="localgaleria">
   <script>
function div_tr_gt(u){
	var gth_y = 'url('+u+')';
	document.getElementById('i-div-imgh').style.backgroundImage = gth_y;
}
</script>

 
   <?php
$pasta = 'imagens/fotos/cachacaria';

if ($handle = opendir($pasta)) {
    
    /* Esta é a forma correta de varrer o diretório */
    while (false !== ($file = readdir($handle))) {
        echo'
<div id="i-div-imgh" class="div-img-pr" style="background-image:url('.$pasta.'/'.$file.');"></div>';
break;
    }

        closedir($handle);
}


echo'<div class="div-galeria">
<table>
<tr>';
 
 foreach(glob(''.$pasta.'/{*.jpg,*.gif}', GLOB_BRACE) as $image) {
	 
	 $img_p = "'";
	 $file = $fotos[] = $image;
	 $gty_array = array("",$img_p,$file,$img_p);
	 $rtyyui = implode("",$gty_array); 
	 
echo'<td><img onClick="div_tr_gt('.$rtyyui.');" src="'.$fotos[] = $image.'" width="50px" height="50px"></td>';
}
echo'</tr></table></div>';
?>

  </div>



 
    
asked by anonymous 19.05.2016 / 01:04

1 answer

0

Your code looks like this:

<div class="localgaleria">
  <script>
    function div_tr_gt(u) {
      var gth_y = 'url(' + u + ')';
      document.getElementById('i-div-imgh').style.backgroundImage = gth_y;
    }
  </script>


  <?php $pasta='imagens/fotos/cachacaria' ; if ($handle=o pendir($pasta)) { /* Esta é a forma correta de varrer o diretório */ while (false !==( $file=r eaddir($handle))) { echo '
<div id="i-div-imgh" class="div-img-pr" style="background-image:url('.$pasta. '/'.$file. ');"></div>'; break; } closedir($handle); } echo '<div class="div-galeria">
<table>
<tr>'; foreach(glob( ''.$pasta. '/{*.jpg,*.gif}', GLOB_BRACE) as $image) { $img_p="'" ; $file=$ fotos[]=$ image; $gty_array=a rray( "",$img_p,$file,$img_p); $rtyyui=i mplode( "",$gty_array); echo '<td><img onClick="div_tr_gt('.$rtyyui. ');" src="'.$fotos[]=$
  image. '" width="50px" height="50px"></td>'; } echo '</tr></table></div>'; ?>

</div>

I believe that what is doing this would be the function OnClick of javascript , so just remove the code from the part where the function appears, thus:

<div class="div-galeria">
 <table>
   <tr>'; foreach(glob( ''.$pasta. '/{*.jpg,*.gif}', GLOB_BRACE) as $image)
        { $img_p="'" ; $file=$ fotos[]=$ image; $gty_array=a rray( "",$img_p,$file,$img_p);
        $rtyyui=i mplode( "",$gty_array); echo '<td><img src="'.$fotos[]=$image. '" 
        width="50px" height="50px">
  </td>'; }
        echo '</tr></table></div>'; 
</div>
    
19.05.2016 / 13:14