Remove inactive class items

2019-08-22 08:55发布

I am trying to make a pagination as shown below by uploading images and adding them to a container by creating new div with new id's and giving class as current for the first page.

If I change to the new page I remove the active class to the current page and add it to the selected page.

I would like to know how do I remove all the inactive pages which do not have class "current"

Here's my code:

<script type="text/javascript">
var imagesPerPage = 4, pageNumber = 1;

function onAjaxSucceded(data) {
    var pagesContainer = $('#pagesContainer'),
        imagesInPage = 0,
        divPage = $("#p1");

    $.each(data.result, function(index, file) {
        if (imagesInPage >= imagesPerPage) {
            imagesInPage = 1;
            pageNumber += 1;
            divPage = $('<div/>', {id : "p" + pageNumber}).addClass('pagedemo').hide().appendTo(pagesContainer);
        } else {
            imagesInPage += 1;
        }
        var src = 'Uploads/' + file.name;
        $('<img>', {src: src, href: src, "class": 'LoadclickImage', align: 'left'}).appendTo(divPage);
    });

    $("#demo5").paginate({
        count: pageNumber,
        start: 1,
        display: Math.min(7, pageNumber),
        border: true,
        border_color: '#fff',
        text_color: '#fff',
        background_color: 'black',
        border_hover_color: '#ccc',
        text_hover_color: '#000',
        background_hover_color: '#fff',
        images: false,
        mouse: 'press',
        onChange: function(page) {
            $('#paginationdemo ._current').removeClass('_current').hide();
            $('#p' + page).addClass('_current').show();
        }
    });
}

var fakeAjaxData = {
    result: [
        {name: '../../../img/keys.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/keys.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
        {name: '../../../img/remove-resources.png'},
        {name: '../../../img/input-button-bg.png'},
        {name: '../../../img/logo.png'},
    ]
};

$(function() {
    onAjaxSucceded(fakeAjaxData);
});
</script>

Here's my demo

EDIT:

Instead of removing inactive class can anyone say me how do I remove all the pages and If I add again I need to add images from the 1st page. as of now If I remove the pages it's adding from the last page it has added.

Excuse me if my tags are wrong.

1条回答
forever°为你锁心
2楼-- · 2019-08-22 09:31

Something like this:

$("#pagesContainer > :not(._current)").remove()
查看更多
登录 后发表回答