【问题标题】:Construct a panel with horizontal scroll bar构造一个带有水平滚动条的面板
【发布时间】:2015-10-16 20:56:40
【问题描述】:

我有一个由我的代码在 twig 上生成的图像列表:

<div class="text-left row">
    <div class="large-12 small-12 columns panel_profile">
    {% for adUser in ad.interestedUsers %}
        {% if adUser.pictureUrl is not empty %}
            <img class="img_interested" id='idPicture_{{ adUser.id }}' src="{{ asset(adUser.getPictureWeb) }}" style="height: 50px; width: 50px;"/>
{% else %}
            {% image 'bundles/delivveweb/images/icon_perfil.png' %}
            <img id='idPicture' src="{{ asset_url }}" style="height: 50px; width: 50px;"/>
            {% endimage %}
        {% endif %}
    {% endfor %}
    </div>
</div>

我的想法是构建一个包含 26 张照片的面板,每行 13 张。当图片数量大于26时,我想水平调出一个rologem bar来查看其他配置文件。

我一直在前端使用foundation-5。

任何人都可以帮助我或知道任何已经这样做的 API 吗? Abaio有一个code pa帮助说明

code

【问题讨论】:

    标签: jquery html css twig zurb-foundation-5


    【解决方案1】:

    首先更改我在 twig 上的代码以通过&lt;li&gt; 生成包含两个图像的列表

     <div class="large-12 small-12 columns horizontal-scroll-panel">
            <ul>
            {% for adUser in ad.interestedUsers %}
                {% if loop.index is divisible by(2) %}
                    <br>
                {% else %}
                    <li>
                {% endif %}
                    {% if adUser.pictureUrl is not empty %}
                        <img class="img_interested" id='idPicture_{{ adUser.id }}' src="{{ asset(adUser.getPictureWeb) }}" style="height: 50px; width: 50px;"/>
                    {% else %}
                        {% image 'bundles/delivveweb/images/icon_perfil.png' %}
                            <img id='idPicture' src="{{ asset_url }}" style="height: 50px; width: 50px;"/>
                        {% endimage %}
                    {% endif %}
                    </li>
                {% endfor %}
            </ul>
        </div>
    

    然后我不得不在 css 中做一些改变以确保放置 scroll-x 的 div 的大小,并授予 &lt;ul&gt; &lt;li&gt;&lt;img&gt; 中的尺寸

    <style>
        .horizontal-scroll-panel {
              width: 600px;
              height: 100px;
              background-color: #ccc;
              padding-bottom: 20px;
              overflow-x: hidden;
              overflow-y: auto;
              -webkit-overflow-scrolling: touch;
              -ms-overflow-style: -ms-autohiding-scrollbar;
              overflow-y: hidden !important;
              overflow-x: auto;
            }
            .horizontal-scroll-panel > ul {
              list-style: none;
              margin: 0;
              padding: 0;
              -webkit-padding-start: 0;
              font-size: 0;
            }
            .horizontal-scroll-panel li {
              display: inline-block;
              border: solid 1px #666;
              box-shadow: 0 0 4px #666;
              width: 50px;
              height: 100px;
              overflow: hidden;
              margin-right: 0px;
              font-size: 0;
            }
            .horizontal-scroll-panel li:first-of-type {
              margin-left: 0 !important;
            }
            .horizontal-scroll-panel li:last-of-type {
              margin-right: 0 !important;
            }
            img {
              height: 50px !important;
              width: 50px !important;
              border: 1px solid red !important;
            }
            [dir=rtl] .horizontal-scroll-panel li {
              margin-right: 0 !important;
              margin-left: 0px !important;
            }
            [dir=rtl] .horizontal-scroll-panel li:first-of-type {
              margin-right: 0 !important;
            }
            [dir=rtl] .horizontal-scroll-panel li:last-of-type {
              margin-left: 0 !important;
            }
    
            @media only screen and (max-device-width: 320px) {
              .horizontal-scroll-panel {
                height: 125px;
                padding: 10px;
              }
              .horizontal-scroll-panel li {
                height: 125px;
                width: 125px;
              }
              .horizontal-scroll-panel img {
                height: 125px !important;
              }
            }
    </style>
    

    最后还有让&lt;li&gt;生成的默认列表变成水平列表的秘诀

    <script>
    $(function() {
          $.fn.extend({
            UIHorizontalScrollPanel : function () {
              return this.each(function() {
                var scrollPanel = $(this).find('ul');
                var panelsWidth = 0;
                scrollPanel.find('li').each(function(_, ctx) {
                    panelsWidth += parseInt($(ctx).outerWidth(true));
                });
                var parentPadding = (parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right')));
                scrollPanel.css('width', (panelsWidth + (parentPadding + parentPadding / 2)));
              });
            }
          });
          $('.horizontal-scroll-panel').UIHorizontalScrollPanel();
        });
    </script>
    

    Function and class that builds a list of images horizontally

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 2016-05-28
      • 1970-01-01
      相关资源
      最近更新 更多