我有一个折叠表单,几乎位于页面底部,问题是当它打开时,用户必须向下滚动才能完全看到它。有没有办法让它在打开时自动向下滚动,如果可能的话,最好让它在关闭时向上滚动?
这是我的代码:
<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>
最佳答案
向您的按钮
添加:onclick="repositionCollapse('#demo')"
和 Javascript,其中 home
是您想要在展开时向上滚动到的元素的 id:
<script>
function repositionCollapse(section)
{
if(location.href == section) location.href = '#home';
else location.href = section;
}
</script>
关于javascript - 使用 bootstrap 向下和向后滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34445889/