gpt4 book ai didi

javascript - jScrollPane 自动加载更多数据

转载 作者:行者123 更新时间:2023-12-02 17:04:58 26 4
gpt4 key购买 nike

好吧,事情是这样的,最近我发现了一个脚本,可以在用户向下滚动时自动加载更多数据。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto Loading Records</title>
<style>
body,td,th {font-family: Georgia, Times New Roman, Times, serif;font-size: 14px; background:#efefef; padding:0; margin:0;}
.animation_image {background: #fff;padding: 10px;width: 500px;margin-right: auto;margin-left: auto;}
#results{width: 500px; margin:0 0 0 17px; padding-bottom: 20px; }
#results ol{margin: 0px;padding: 0px;}
#results li{margin: 10px 0px; padding: 10px 0px; border-bottom:1px dotted #999; }
.container {
position: relative;
height: 600px;
width: 600px;
overflow: auto;
margin:0 auto;
background:#fff;
margin-top: 30px;
border:1px solid #ddd;
}

.content {
position: relative;
height: auto; /* height just added for illustrative purposes */
width: 550px;
background:#fff;
}
</style>
</head>

<body>

<div id="container" class="container">
<div class="content">
<ol id="results"></ol>
<div class="animation_image" style="display:none" align="center"><img src="ajax-loader.gif"></div>
</div>
</div>

<script type="text/javascript" src="js/jquery-min.1.10.2.js"></script>
<?php
include("config.php");
$results = $mysqli->query("SELECT COUNT(*) as t_records FROM paginate");
$total_records = $results->fetch_object();
$total_groups = ceil($total_records->t_records/$items_per_group);
$results->close();
?>
<script type="text/javascript">
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
var loading = false; //to prevents multipal ajax loads
var total_groups = <?php echo $total_groups; ?>; //total record group(s)
$('#results').load("autoload_process.php", {'group_no':track_load}, function() {track_load++;}); //load first group
$('#container').scroll( function() {
var fromtop = $(this).scrollTop(),
height = $(this).find('.content').innerHeight() - $(this).innerHeight();

if ((height - fromtop) < 50) {
if(track_load <= total_groups && loading==false) //there's more data to load
{
loading = true; //prevent further ajax loading
$('.animation_image').show(); //show loading image

//load data from the server using a HTTP POST request
$.post('autoload_process.php',{'group_no': track_load}, function(data){

$("#results").append(data); //append received data into the element

//hide loading image
$('.animation_image').hide(); //hide loading image once data is received

track_load++; //loaded group increment
loading = false;

}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?

alert(thrownError); //alert with HTTP error
$('.animation_image').hide(); //hide loading image
loading = false;
});
}
}
});
});
</script>

</body>
</html>

一切正常。但是当我尝试实现 jScrollPane 以使滚动条更平滑时,该脚本不起作用。谁能帮助我吗?

最佳答案

我想发表评论,但似乎我的声誉不够高,无法发表评论。因此,回复。

我看了一下 jScrollPane,它似乎监听了鼠标的“scroll”事件并使用 window.scrollBy 进行滚动,并导致 jQuery 的 .scroll 不触发。虽然我不能保证这就是它不会触发的原因(我假设这就是你的代码无法工作的原因),因为我对 javascript 的了解非常有限。

更换

$(element).scroll(function () {});

$(element).on('mousewheel DOMMouseScroll', function() {});

应该修复它。我认为...为什么会这样,你可能应该问别人,因为我只会引起困惑。

关于javascript - jScrollPane 自动加载更多数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25331377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com