I want to show multiple images on product detail page dynamically in php.I have an image_arr for each product.If I click on any of the thumb images,the zoom image should change.This is what I have tried but I know its not correct as when I click on thumbnail,the image opens in the entire tab replacing my current url and page.
<?php
foreach($product_detail as $row):
$image_arr = $row['product_images'];
$first_image = $row['product_images'][0]['image_name'];
?>
<div class="col-md-6 single-right-left ">
<div class="easyzoom easyzoom--overlay easyzoom--with-thumbnails">
<a href="<?php echo base_url(); ?>images/product_detail_images/<?php echo $first_image;?>">
<img src="<?php echo base_url(); ?>images/product_detail_images/<?php echo $first_image;?>" alt="" class="main-image" />
</a>
</div>
<ul class="thumbnails">
<?php foreach($image_arr as $curr_img):
$prod_image = base_url().'images/product_detail_images/'.$curr_img['image_name'];
?>
<li>
<a href="<?php echo $prod_image; ?>" data-standard="images/detail-small-1.png">
<img src="<?php echo $prod_image; ?>" alt="" class="thumnail-main" />
</a>
</li>
<?php endforeach;?>
</ul>
</div>
This snippet will do what my comment suggests. Tailor it for your needs.
$('.image').on('click', function(){
$(this).toggleClass('zoomed');
});
.zoomed {
transform: scale(1.5);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRJRgf_toK_QNtnosM2jkTY3-e4rprTz9DQs8uwI2bSzxp76ho90Q" class="image" />
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTgcNyT2aqDrvJO9CE__3S-8FHg2xRrSbgqYog8iZMZUIacCO3Q" class="image" />
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRj6Pwwf32O7KHMNK_TGQrfhEL05iOjW0GyiPlapAnf9l8oq883" class="image" />
Misread the question a bit... so I'll expand...
This snippet will take a click on a thumbnail, and make a separate but related image bigger...
$('.image').on('click', function(){
var thumbnail = $(this).data('thumbnail');
$('.thumbnail[data-zoom="image_1"]').toggleClass('zoomed');
});
.zoomed {
transform: scale(1.5);
}
.image {
width:50px;
height:50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTgcNyT2aqDrvJO9CE__3S-8FHg2xRrSbgqYog8iZMZUIacCO3Q" data-thumbnail="image_1" class="image" />
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTgcNyT2aqDrvJO9CE__3S-8FHg2xRrSbgqYog8iZMZUIacCO3Q" data-zoom="image_1" class="thumbnail" />
</div>