Sehen Sie sich diese Plunker
JS:
$(document).ready(function() {
var loadVar, numbOfElements=0, count, elementsPerPage = 5,
currentPage, numberOfPage;
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
contentType:"text/xml",
async:false,
success: function(xml) {
loadVar = xml;
loadImages("ADOBE");
showImages();
disableEnableBtns();
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
$("#adobe").click(function() {
loadImages("ADOBE");
showImages();
disableEnableBtns();
});
$("#mac").click(function() {
loadImages("MAC");
showImages();
disableEnableBtns();
});
var sTitle, countEach;
function loadImages(loadNodeValues) {
$("#thumbnails").empty();
numbOfElements=0
$(loadVar).find(loadNodeValues).each(function(i,item) {
var sTitle = "<section class='small count"+(i+1)+"'><h2>" + $(item).find("CAPTION").text() + "</h2><span>" +$(item).find("LINK").text() + "</span></section>";
$("#thumbnails").html($("#thumbnails").html()+sTitle);
numbOfElements++;
});
numberOfPage = numbOfElements/elementsPerPage;
}
function showImages() {
$('.small').hide();
for (i = 1; i <= elementsPerPage; i++) {
$('.small').each(function() {
if ($(this).hasClass('count' + i)) {
$(this).show();
}
});
}
currentPage = 0;
}
function disableEnableBtns() {
if (thumbnails.children.length <= elementsPerPage) {
$("#rightBtn").prop("disabled", true);
$("#leftBtn").prop("disabled", true);
} else {
$("#rightBtn").prop("disabled", false);
$("#leftBtn").prop("disabled", false);
}
$("#leftBtn").prop("disabled", true);
}
$("#rightBtn").click(function() {
currentPage++;
$('.small').hide();
var limit = elementsPerPage * (currentPage + 1) > numbOfElements ? numbOfElements : elementsPerPage * (currentPage + 1);
for (i = (currentPage * elementsPerPage) + 1; i <= limit ; i++) {
$('.small').each(function() {
if ($(this).hasClass('count' + i)) {
$(this).show();
}
});
if(i == numbOfElements)
{
$("#rightBtn").prop("disabled", true);
$("#leftBtn").prop("disabled", false);
}
else
{
$("#rightBtn").prop("disabled", false);
$("#leftBtn").prop("disabled", false);
}
}
});
$("#leftBtn").click(function() {
currentPage--;
$('.small').hide();
for (i = (currentPage * elementsPerPage) + 1; i <= elementsPerPage * (currentPage + 1); i++) {
$('.small').each(function() {
if ($(this).hasClass('count' + i)) {
$(this).show();
}
});
if(i == 5)
{
$("#rightBtn").prop("disabled", false);
$("#leftBtn").prop("disabled", true);
}
else
{
$("#rightBtn").prop("disabled", false);
$("#leftBtn").prop("disabled", false);
}
}
});
});
Vielen Dank für die vorherige Festsetzung der nächsten und Top-Link Tasten issues.Can Sie mich mit dem Navigations Problem helfen nur durch Knoten in ‚elementsPerPage‘ zu ersetzen, ohne mit hide() und show(). Das wäre eine große Hilfe. – jake
Überprüfen Sie [Plunker] (http://pnnr.co/edit/HJKy8iYNX2CgUqJJM7IU?p=preview). – RonyLoud
Vielen Dank für die Hilfe. Ich schätze viel. Du hast gerade meinen Tag gemacht! Ich habe auch etwas Neues gelernt. Sie haben auch weniger Codezeilen erstellt. Noch einmal vielen Dank. – jake