繁体   English   中英

使用引导程序向下滚动和向上备份

[英]Scrolling down and back up with bootstrap

我有一个折叠表单,该折叠表单几乎位于页面的底部,问题是打开它时,用户将不得不向下滚动才能完全看到它。 有没有办法让它在打开时自动向下滚动,甚至在可能的情况下在关闭时向上滚动呢?

这是我的代码:

<style type="text/css">
    .bs-example{
        margin: 20px;
    }
    .table-nonfluid {
        width: auto !important;
    }
</style>
     <div class="container">
      <button  type="button" class="btn btn-info" data-toggle="collapse" data-target="#demo">Status Updates</button>
      <div id="demo" class="collapse">


    <div class="bs-example">
    <table class="table table-bordered table-nonfluid">
    <thead>
    <tr>
    <th>Time</th>
    <th>Update</th>
    </tr>
    </thead>
    <tbody>

    <tr class="active">
    <td>Jan 5</td>
    <td>Demo 2</td>
    </tr>

    <tr class="active">
    <td>Jan 4</td>
    <td>Demo 1</td>
    </tr>

    </tbody>
    </table>
    </div>

在您的button添加: onclick="repositionCollapse('#demo')"

和Javascript,其中home是要折叠时要向上滚动到的元素的ID:

<script>
function repositionCollapse(section)
{
    if(location.href == section) location.href = '#home';
    else location.href = section;
}
</script>

暂无
暂无

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

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