简体   繁体   English

如何滚动元素以为扩展元素留出空间

[英]How to scroll elements to make space for expanding element

I've got the following div hierarchy in my page! 我的页面中有以下div层次结构!

<div id="bill-list">
    <div id="bill-panel">
    <!-- Bill -->
         <div class="bill">
         <!-- Bill description - Holds Bill details -->
         <div class="bill-description">
            <div class="bill-info bill-number"><span>000A</span></div>
            <div class="bill-info table-name"><span>TABLE 78</span></div>
            <div class="bill-info room-number"><span>A678</span></div>
                            <div class="bill-info amount"><span>76.00 USD</span></div>
            <div class="bill-remove-icon"></div>
         </div>

         <!-- Bill Item list -->
         <div class="bill-item-list">

         <!-- Item : This is a sample element & will be cleared when system loads -->
         <div class="bill-item">

            <!-- Item image -->
            <div class="bill-item-img"></div>
            <!-- Item description -->
            <div class="bill-item-description">
            <div class="bill-item-name">

            <!-- Item Name -->
            <p class="bill-item-name-left">Normal Cofee</p>
            <!-- Item Price -->
            <p class="bill-item-name-right">170.00</p>
            <div class="clear"></div>
        </div>
        <!-- Total item price -->
        <div class="bill-item-price">
        <span>170.00 USD</span>
        </div>

        <!-- Item Quantity -->
        <div class="bill-item-amount">
        <span>1</span>
    </div>

    </div>
    <!-- Increas & Decrease item Quantity -->
    <div class="bill-amount-selection">
    <a class="amount-increase" href="#"></a>
    <a class="amount-decrease" href="#"></a>
    </div>
    </div>

    <!-- Remove bill link -->
    <div class="item-drop-point"></div>
    </div>
    </div>
    </div>                      

</div>

I'm designing a web application where I load the bills and create each bill using jQuery. 我正在设计一个Web应用程序,在其中加载帐单并使用jQuery创建每个帐单。 So I create each element of bill and append them to the bill panel! 因此,我创建了Bill的每个元素并将它们附加到Bill面板! I've enabled scrolling of the bill list using the following code. 我已经启用了使用以下代码滚动帐单列表的功能。 I've used dragscroller as the scrolling plugin. 我已经使用dragscroller作为滚动插件。

$('#bill-list').dragscrollable({dragSelector: '#bill-panel', acceptPropagatedEvent: true});

And the bill has a click event of it's own where I expand the bill using jQuery slide toggle. 帐单中有一个单击事件,这是我自己的事件,在这里我使用jQuery滑动切换扩展帐单。

$(document).on('click',".bill-description",function()
{
    //close all bills 
    $(".bill-item-list").not($(this).next(".bill-item-list")).slideUp(600);
    //open the clicked bills
    $(this).next(".bill-item-list").slideToggle(600);

});

The above code closes any other element that is open and expand the clicked bill. 上面的代码关闭了所有其他打开的元素,并展开了单击的帐单。 Following is the CSS used for the elements. 以下是用于元素的CSS。

#bill-list {
  max-height: 581px;
  overflow: hidden;
}
  #bill-panel {
  max-height: 575px;
}
.bill {
    width: 100%;
    margin-top: 2px;
}
.bill-description {
    height: 30px;
    font-family: MyriadProReg;
    background-color: rgb(214, 214, 214);
    cursor: pointer;
}

All these effects work fine. 所有这些效果都很好。 The problem is when I expand an element that is in the bottom of the bill panel, it gets expanded, but I have to manually scroll to view the expanded section. 问题是,当我展开“帐单”面板底部的元素时,它会被展开,但是我必须手动滚动以查看展开的部分。 I've go no idea on how to fix it! 我不知道如何解决它!

What I need is a help to do the following. 我需要帮助来执行以下操作。 There is a list of bills that can be scrolled. 有可以滚动的账单清单。 Each bill has around 5 bill items. 每个账单大约有5个账单项。 and when I expand an element at the bottom of the bill panel, bills should auto scroll to show the expanded bill. 当我在“帐单”面板底部展开一个元素时,帐单应自动滚动以显示展开的帐单。

在此处输入图片说明

Have you tried using the jQuery scrollTo() plugin? 您是否尝试过使用jQuery scrollTo()插件? It may be helpful in this case. 在这种情况下可能会有所帮助。 Info and download here . 信息并在此处下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM