Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,37 @@
text-align: center;
}
h1, h2 {
max-width: 80%;
font-size: 300;
max-width:80%;
}
.fs-gal {
width: 100px;
height: auto;
float: left;
width: auto;
height: 100px;
}
</style>
</head>
<body>

<!-- Create objects with class 'fs-gal' and include the data-attribute 'data-url' with the relative or absolute path which is to be displayed. -->
<!-- <img class="fs-gal" src="img/example1.jpg" alt="Example Image 1" data-url="img/example1.jpg" />
<img class="fs-gal" src="img/example2.jpg" title="Example Image 2" data-url="img/example2.jpg" />
<img class="fs-gal" src="img/eiffel.jpg" data-url="img/eiffel.jpg" />
<img class="fs-gal" src="img/panorama.jpg" data-url="img/panorama.jpg" /> -->
<img class="fs-gal" src="img/example1.jpg" alt="Example Image 1" data-url="https://images.pexels.com/photos/443446/pexels-photo-443446.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=1701&w=2633" />
<!--

Create objects with class 'fs-gal' and include the data-attribute 'data-url' with the relative or absolute path which is to be displayed.
If data-url is not specified, "src" attribute will be used as image path.
You can also have multiple galleries by using data-gallery attribute in order to create different groups

-->

<h3>Gallery 1</h3>
<img class="fs-gal" src="img/example1.jpg" alt="Example Image 1" data-url="https://images.pexels.com/photos/443446/pexels-photo-443446.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=1701&w=2633" />
<img class="fs-gal" src="img/example2.jpg" title="Example Image 2" data-url="https://images.pexels.com/photos/374710/pexels-photo-374710.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=1701&w=2633" />
<img class="fs-gal" src="img/eiffel.jpg" data-url="img/eiffel.jpg" />
<img class="fs-gal" src="img/panorama.jpg" data-url="img/panorama.jpg" />
<hr/>
<h3>Gallery 2</h3>
<img class="fs-gal" data-gallery='gal_02' src="img/awat.jpg" />
<img class="fs-gal" data-gallery='gal_02' src="img/machu.jpg" />
<hr/>
<h3>Gallery 3</h3>
<img class="fs-gal" data-gallery='gal_03' src="img/carnac.jpg" />

<!-- Full screen gallery -->
<div class="fs-gal-view">
Expand Down
Binary file added img/awat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/carnac.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/machu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 49 additions & 18 deletions js/fs-gal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,81 @@ $('document').ready(function() {
imgElem = $('.fs-gal-main');
imgElem.attr('title', title);
imgElem.attr('alt', alt);
imgElem.attr('src', obj.attr('data-url'));
imgElem.attr('src', obj.attr('data-url') ? obj.attr('data-url') : obj.attr('src'));
$('.fs-gal-view > h1').text(title);
if (!title || title == '') { $('.fs-gal-view > h1').fadeOut(); }
else { $('.fs-gal-view > h1').fadeIn(); }

// Create buttons
var current = $('.fs-gal').index(obj);
// Create buttons
var gallery = $(obj).attr('data-gallery');
var selector = gallery ? '.fs-gal[data-gallery="'+gallery+'"]' : '.fs-gal:not([data-gallery])';
var current = $(selector).index(obj);
var prev = current - 1;
var next = current + 1;
if (prev >= 0) {
$('.fs-gal-view > .fs-gal-prev').attr('data-img-index', prev);
if(gallery)
$('.fs-gal-view > .fs-gal-prev').attr('data-gallery',gallery);

$('.fs-gal-view > .fs-gal-prev').fadeIn();
}
if (next < $('.fs-gal').length) {

var length = gallery ? $('.fs-gal[data-gallery="'+gallery+'"]').length : $('.fs-gal:not([data-gallery])').length;

if (next < length) {
$('.fs-gal-view > .fs-gal-next').attr('data-img-index', next);
if(gallery)
$('.fs-gal-view > .fs-gal-next').attr('data-gallery',gallery);
else
$('.fs-gal-view > .fs-gal-next').removeAttr('data-gallery');

$('.fs-gal-view > .fs-gal-next').fadeIn();
}
$('.fs-gal-view').fadeIn(); // Display gallery
if (current == $('.fs-gal').length - 1) { // Last image
if (current == length - 1) { // Last image
$('.fs-gal-view > .fs-gal-next').attr('data-img-index', 0);
$('.fs-gal-view > .fs-gal-next').fadeIn();

if(gallery)
$('.fs-gal-view > .fs-gal-next').attr('data-gallery',gallery);
else
$('.fs-gal-view > .fs-gal-next').removeAttr('data-gallery');

}
else if (current == 0) { // Last image
else if (current == 0) { // first image
$('.fs-gal-view > .fs-gal-prev').attr('data-img-index', $('.fs-gal').length - 1);
$('.fs-gal-view > .fs-gal-next').fadeIn();
if(gallery)
$('.fs-gal-view > .fs-gal-prev').attr('data-gallery',gallery);
else
$('.fs-gal-view > .fs-gal-prev').removeAttr('data-gallery');

}


if(length > 1)
$('.fs-gal-view > .fs-gal-next').fadeIn();
else
$('.fs-gal-view > .fs-gal-next').fadeOut();

// preload next images
preloadNextAndPrev();
preloadNextAndPrev(gallery);

}

// Preload next and previous image
function preloadNextAndPrev() {
function preloadNextAndPrev(gallery) {
fs_gal_preloads = new Array();
// previous
index = $('.fs-gal-view > .fs-gal-prev').attr('data-img-index');
elem = $($('.fs-gal').get(index));
img = elem.attr('data-url');
preloadImage(img);
elem = gallery ? $($('.fs-gal[data-gallery="'+gallery+'"]').get(index)) : $($('.fs-gal:not([data-gallery])').get(index));
img = elem.attr('data-url') ? elem.attr('data-url') : elem.attr('src');
if(img)
preloadImage(img);
// next
index = $('.fs-gal-view > .fs-gal-next').attr('data-img-index');
elem = $($('.fs-gal').get(index));
img = elem.attr('data-url');
preloadImage(img);
elem = gallery ? $($('.fs-gal[data-gallery="'+gallery+'"]').get(index)) : $($('.fs-gal:not([data-gallery])').get(index));
img = elem.attr('data-url') ? elem.attr('data-url') : elem.attr('src');
if(img)
preloadImage(img);
}

// Preload an image
Expand All @@ -88,8 +118,9 @@ $('document').ready(function() {
// Gallery navigation
$('.fs-gal-view .fs-gal-nav').click(function(e) {
e.stopPropagation();
var index = $(this).attr('data-img-index');
var img = $($('.fs-gal').get(index));
var index = $(this).attr('data-img-index');
var gallery = $(this).attr('data-gallery');
var img = gallery ? $($('.fs-gal[data-gallery="'+gallery+'"]').get(index)) : $($('.fs-gal:not([data-gallery])').get(index));
fsGal_DisplayImage(img);
});

Expand Down