moses toh moses toh - 1 year ago 73
Javascript Question

How to add pagination in photo gallery?

My HTML Code is like this :

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>

<div class="modal-body">

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- /.modal-content -->
<!-- /.modal-dialog -->
<!-- /.modal -->

My Javascript Code is like this :

htmlData = '';
htmlData = 'Photos<a href="#" id="hotel_photo" data-hotel-code="nases">(Click to View)</a><br><br>';
htmlData += '<div class="imageHotel"></div>';


$(document).on("click", "#hotel_photo", function(event){
htmlData += '<div id="gallery_hotel">';

htmlData = '<img id="largeImage" src="" />';

htmlData += '</div>';

htmlData += '<div id="thumbs_hotel">';

htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';
htmlData += '<img src="" />';

htmlData += '</div>';


// bind the click event
$('#thumbs_hotel').off().on('click', 'img', function () {


Demo is like this :

I want add pagination in my photo gallery. So the images shown only 5 pictures per page. for example, there are 10 pictures, then there will be 2 page

Any solution to solve my problem?

Thank you very much

Answer Source

I have used owl carousel for this.

    items: 5, // number of images to be moved
    dots: true

I have prevented swipe/touch/drag event for owl carousel by adding following code:

$(".item").on("touchstart mousedown", function(e) {
    // Prevent carousel swipe

Also I have added css for navigation dots. You can change it according to requirement.

.owl-carousel .item {
    margin: 3px;
.owl-dot {
    display: inline-block;
.owl-dots span {
    background: none repeat scroll 0 0 #869791;
    border-radius: 20px;
    display: block;
    height: 12px;
    margin: 5px 7px;
    opacity: 0.5;
    width: 12px;

Please refer the fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download