-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallery.js
67 lines (57 loc) · 1.64 KB
/
gallery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function($){
// Caption
$('.entry').each(function(i){
$(this).find('img').each(function(){
if (!$(this).hasClass('nofancybox')){
var alt = this.alt;
if (alt){
$(this).after('<span class="caption">' + alt + '</span>');
}
$(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox" rel="gallery' + i + '" />');
}
});
});
// Gallery
var play = function(parent, item, callback){
var width = parent.width();
item.imagesLoaded(function(){
var _this = this[0],
nWidth = _this.naturalWidth,
nHeight = _this.naturalHeight;
callback();
this.animate({opacity: 1}, 500);
parent.animate({height: width * nHeight / nWidth}, 500);
});
};
$('.gallery').each(function(){
var $this = $(this),
current = 0,
photoset = $this.children('.photoset').children(),
all = photoset.length,
loading = true;
play($this, photoset.eq(0), function(){
loading = false;
});
$this.on('click', '.prev', function(){
if (!loading){
var next = (current - 1) % all;
loading = true;
play($this, photoset.eq(next), function(){
photoset.eq(current).animate({opacity: 0}, 500);
loading = false;
current = next;
});
}
}).on('click', '.next', function(){
if (!loading){
var next = (current + 1) % all;
loading = true;
play($this, photoset.eq(next), function(){
photoset.eq(current).animate({opacity: 0}, 500);
loading = false;
current = next;
});
}
});
});
})(jQuery);