mirror of
https://github.com/wahyd4/hexo-phase-junv.git
synced 2026-08-09 13:05:52 +10:00
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
(function($){
|
|
// Caption
|
|
$('.entry-content').each(function(i){
|
|
$(this).find('img').each(function(){
|
|
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); |