【问题标题】:Toggle set of images with btn-group使用 btn-group 切换图像集
【发布时间】:2016-02-02 16:17:00
【问题描述】:

我不想一次显示所有图像,因为它只会使页面设计混乱。我想单击引导 btn 组中的一个按钮,然后显示相应的图像。不是 javascript/jquery 人,所以我需要一点帮助。

  <div class="btn-group" role="group" aria-label="...">
    <button type="button" class="btn btn-default">Front</button>
    <button type="button" class="btn btn-default">Back</button>
    <button type="button" class="btn btn-default">Left</button>
    <button type="button" class="btn btn-default">Right</button>
  </div>

  <div class="front-product-img">
    <% front = @product['colors'][0]['images'].find{|img| img['label'] == 'Front'} %>
    <%= image_tag front['url'], class: 'img-responsive' if front.present? %>
  </div>

  <div class="back-product-img">
    <% back = @product['colors'][0]['images'].find{|img| img['label'] == 'Back'} %>
    <%= image_tag back['url'], class: 'img-responsive' if back.present? %>
  </div>

  <div class="left-product-img">
    <% left = @product['colors'][0]['images'].find{|img| img['label'] == 'Left'} %>
    <%= image_tag left['url'], class: 'img-responsive' if left.present? %>
  </div>

  <div class="right-product-img">
    <% right = @product['colors'][0]['images'].find{|img| img['label'] == 'Right'} %>
    <%= image_tag right['url'], class: 'img-responsive' if right.present? %>
  </div>

【问题讨论】:

    标签: javascript jquery ruby-on-rails twitter-bootstrap


    【解决方案1】:
    $(".btn-group[role='group'] button[type=button]").click(function() {
    $("."+$(this).text().toLowerCase()+"-product-img").toggle();
    });
    

    根据您的要求使用上面的代码..

    【讨论】:

    • 不太对,关闭。我什至无法描述它在做什么,因为每次重新加载时它都会做不同的事情。首先它显示页面加载时的所有图像。当我单击前面的 btn 时,它会显示回来,然后它不再显示该 img。希望我能更好地描述它,但我对它在做什么感到困惑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2018-08-16
    • 2014-01-03
    • 2010-09-25
    • 1970-01-01
    相关资源
    最近更新 更多