Php 在用户滚动时生成更多文章
我正在建立一个网站,允许用户上传图像、GIF和视频。在主页上,我想有一个人们上传的文件列表,最好是基于受欢迎程度,但我还不太了解。当页面第一次加载时,我希望根据用户屏幕分辨率显示一定数量的文件。在加载更多文件之前,用户可以在其中向下滚动一点。我现在的代码如下所示:Php 在用户滚动时生成更多文章,php,ajax,html,loading,Php,Ajax,Html,Loading,我正在建立一个网站,允许用户上传图像、GIF和视频。在主页上,我想有一个人们上传的文件列表,最好是基于受欢迎程度,但我还不太了解。当页面第一次加载时,我希望根据用户屏幕分辨率显示一定数量的文件。在加载更多文件之前,用户可以在其中向下滚动一点。我现在的代码如下所示: <article class="item thumb" data-width="282"> <h2><?php echo $file_title;?></h2> &l
<article class="item thumb" data-width="282">
<h2><?php echo $file_title;?></h2>
<a href="<?php echo $randomImage ?>"><img src="<?php echo $randomImage ?>" alt=""></a>
</article>
<article class="item thumb" data-width="384">
<h2><?php echo $file_title;?></h2>
<a href="<?php echo $randomImage ?>"><img src="<?php echo $randomImage ?>" alt=""></a>
</article>
它总共做了8次。我怎样才能让页面在用户滚动时请求更多的标签…就像Facebook在你向下滚动时加载更多的内容一样?对不起,我解释得不好 您应该查看window.onscroll事件,在这里您可以连接到当有人在您的页面上滚动窗口时要调用的函数。然后,您可以决定是否需要加载更多内容 与往常一样,MDN对此有一些文档。过来看
我在我的网页上使用此方法,在这里我检查用户是否已几乎滚动到页面底部(从底部开始滚动200px),然后我将向现有元素添加一些数据 我有一个DIV(#main),读取最后一个条目的ID,然后将这个ID传递到AJAX页面,并添加更多ID更高的条目
$(document).ready(function() {
// Check if we have scrolled to the bottom (trigger 200px from bottom)
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 200) {
// Get the ID on the last DIV
var lastDiv = $("#main").find("div:last");
var lastID = lastDiv.attr("id");
// Get the new weblog
ajaxGet(lastID);
}
});
// ajaxSend will send all form data for processing
// -----------------------------------------------
function ajaxGet (id) {
$.ajax({
url: "weblog_ajax.php",
type: "get",
data: { wid : id },
async: false
}).done(function(data) {
$("#main").append(data); // append a new DIV
}).fail(function(data) {
// do something if it fails
}).always(function(data) {
// always do something
});
} // function ajaxSend
});
可能重复看看9gag的源代码,它们完全按照您的要求执行。所以,我只想加载更多带有随机图像的块。我该如何编写“url:*”引用的页面中的代码?我是否将当前加载随机文件的代码放入主页的文章标记中?或者ajax php文件是否需要采用某种特殊格式?