0
我想使用動畫函數滾動到表的特定行。當可滾動div處於頂部時它工作正常,但當我從頂部滾動時,它只能看到看起來可見的頂部。使用scrollTop:tableRow.offset()。頂部內滾動div,只顯示從頂部可見的距離
我在對話框(Bootstrap Modal窗口)中使用這個。有沒有辦法讓距離頂部的距離不只是可見?下面
HTML代碼是一個asp.net mvc4部分類,進入一個引導模態窗口(對話框)的一部分:
<div id="LocationNumberModalAllLocations" style="Margin-top: -9px">
<div class="container">
<div class="row row-eq-height">
<div class="col-sm-12 col-md-4">
<div id="LocationNumberModalAllLocationsSelectionContainer" class="ModalResultsTable">
<table id="locationList" class="table table-hover table-condensed">
<thead>
<tr>
<th>Location</th>
<th>Items</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="col-sm-12 col-md-8 modalTableColumnCanvas">
<center><div id="control" style="Margin:-11px 0 5px 0">
Go to location: <input type="text" size="10" id="GoToLocationInput" /> <button onclick='gotoLocation()'> Go </button>
</div></center>
<div class="modalTableCanvas">
<div class="ModalSelectedTable">
<center><h4>Selected Location's Inventory</h4></center>
</div>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Part Number</th>
<th>Condition</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
這裏是我的jQuery代碼。
function gotoLocation() {
//check if value exists
var tableOfLocations = $('#locationList');
var location = $('#GoToLocationInput').val();
var tableRow = $('#locationList tbody tr td').filter(function() {
return $(this).text() == location;
});
if (tableRow.length) {
var container = $('#LocationNumberModalAllLocationsSelectionContainer');
var height = container.height();
var tableRowPosition = tableRow.offset().top;
container.animate({ scrollTop: tableRowPosition - (height/2) }, 1000);
}
}
示例: jsfiddle.net/eaglei22/vgutew90
你可以發佈你的HTML嗎? –
@ObsidianAge好的,我發佈了與該函數一起使用的html。 – eaglei22
按照原樣複製你的代碼給了我'gotoLocation沒有被定義'。你有沒有遇到同樣的錯誤? –