我目前正在使用以下代码进行分页。我正在寻找一种方法让页面滚动到页面切换上的内容列表的开头。 Example of page here.非常感谢任何帮助,谢谢!
(function($){
$.fn.customPaginate = function(options)
{
var paginationContainer = this;
var itemsToPaginate;
var defaults = {
itemsPerPage : 4
};
var settings = {};
$.extend(settings, defaults, options);
var itemsPerPage = settings.itemsPerPage;
itemsToPaginate = $(settings.itemsToPaginate);
var numberOfPaginationLinks = Math.ceil((itemsToPaginate.length / itemsPerPage));
$("<ul></ul>").prependTo(paginationContainer);
for(var index = 0; index < numberOfPaginationLinks; index++)
{
paginationContainer.find("ul").append("<li>"+ (index+1) + "</li>");
}
itemsToPaginate.filter(":gt(" + (itemsPerPage - 1) + ")").hide();
paginationContainer.find("ul li").on('click', function(){
var linkNumber = $(this).text();
var itemsToHide = itemsToPaginate.filter(":lt(" + ((linkNumber-1) * itemsPerPage) + ")");
$.merge(itemsToHide, itemsToPaginate.filter(":gt(" + ((linkNumber * itemsPerPage) - 1) + ")"));
itemsToHide.hide();
var itemsToShow = itemsToPaginate.not(itemsToHide);
itemsToShow.show();
});
}
}(jQuery));
答案 0 :(得分:0)
单击paginate按钮时使用
$('html, body').animate({scrollTop : 0},800);