duanmian1085 2019-02-04 14:07
浏览 181

动态php缩放图像点击缩略图

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>
  • 写回答

1条回答 默认 最新

  • dpa89292 2019-02-04 14:53
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘