【发布时间】:2019-09-23 10:46:23
【问题描述】:
您好,我正在使用 ruby-2.2.2 和 rails 4 开发一个 ROR 项目。我已经在我的网页中实现了无限滚动到特定区域(特定于 div)并且它工作正常,但是每当添加水平滚动时通过增加表格的宽度或增加表格内“td”的数量到该 div,它会在单个滚动上发送对同一页面的多个请求。
html page:
<div class="ibox-content" style="height: 450px;overflow-y: scroll;" id="user_mangmnet_scroll_div">
<table class="table table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Zipcode</th>
<th>Phone Number</th>
<th>Email</th>
<th>User Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="user_management_container">
<%= render 'dashboard/dashboards/admin/user_managment.html.erb' %>
</tbody>
</table>
</div>
<div id="user-pagination-container">
<%= will_paginate @user_registered %>
</div>
jQuery:
$(document).ready(function() {
if ($('#user-pagination-container .pagination').length) {
$('#user_mangmnet_scroll_div').scroll(function() {
var url = $('#user-pagination-container .pagination .next_page').attr('href');
if(url && ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight)) {
return $.getScript(url);
}
});
return $('#user_mangmnet_scroll_div').scroll();
}
});
问题是每当我向 div 添加水平滚动时,它都会在单个滚动上发送对同一页面的多个请求。
请帮助提前谢谢:)
【问题讨论】:
标签: javascript jquery html css ruby-on-rails