我有一个这样的视图文件:
<html>
<head>
<meta name="layout" content="main" />
<title><g:message code="User's profile" /></title>
<g:javascript library="jquery"/>
<g:javascript>
(function() {
jQuery(function() {
return $(window).scroll(function() {
var url;
url = $('.pagination .nextLink').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
$('.pagination').show();
$('.pagination').text('Fetching more tasks, please wait!...');
return $.get(url, function(data) {
$('#scrolling').append(data);
return $('.pagination').hide();
});
}
});
});
}).call(this);
</g:javascript>
</head>
<body>
<!--Render the menu for the user-->
<!--check the size of the task so that we can diplay a meaningful mess if userTasks is empty!-->
<g:if test = "${userTasks.size() > 0}" >
<div id = "scrolling">
<g:each in = "${userTasks}" var = "tasks">
<div class = "scrolling">
<span style = "position:relative; left:360px; font-size:1.2em;"><g:link controller = "tasks" action = "show2" id = "${tasks.id}">${tasks.title}</g:link> </span>
</div>
</g:each>
<div class = "pagination">
<g:paginate total = "${tasksCount}" controller = "tasks" action = "test" />
</div>
</g:if>
<g:else>
You don't have any unread tasks!
</g:else>
</div>
<br />
</body>
</html>
这与Twitter网站非常相似,当用户向下滚动页面底部时,i / e将获取更多结果,这将重复进行。这对我有用,但我现在遇到的问题不是单独更新我的id scrolling
部分,而是让整个页面再次重新加载并使页面看起来很讨厌!
以下是我的网页外观:
当我的滚动条点击页面底部时,您可以清楚地看到我的整页布局正在重新加载。我怎么能摆脱这个?
提前致谢。
答案 0 :(得分:1)
试试这个:
(function() {
jQuery(function() {
return $(window).scroll(function() {
var url;
url = $('.pagination .nextLink').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
$('.pagination').show();
$('.pagination').text('Fetching more tasks, please wait!...');
$.get(url, function(data) {
$("#scrolling").append($(data).filter("#scrolling").html());
$('.pagination').hide();
});
return $('#scrolling').load(url + " #scrolling", function() {
return $('.pagination').hide();
});
}
});
});
}).call(this);