单击缩略图时动态php缩放图像

时间:2019-02-04 14:07:55

标签: php image zoom thumbnails easy-thumbnails

我想在php中动态在产品详细信息页面上显示多个图像。我为每个产品都有一个image_arr。如果单击任何拇指图像,则缩放图像都应该更改。这是我尝试过的,但是我知道它不正确,因为当我单击缩略图时,图像在整个选项卡中打开,替换了我当前的网址和页面。

    <?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>

1 个答案:

答案 0 :(得分:0)

此代码段将执行我的评论所建议的操作。根据您的需求量身定制。

$('.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" />

误解了这个问题...所以我会继续扩展...

此代码段将单击缩略图,并放大单独但相关的图像...

$('.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" />