hexo-theme-amane/source/js/main.js

64 lines
2.2 KiB
JavaScript

(function($){
var toTop = ($('#sidebar').height() - $(window).height()) + 60;
// Caption
$('.article-entry').each(function(i) {
$(this).find('img').each(function() {
if (this.alt && !(!!$.prototype.justifiedGallery && $(this).parent('.justified-gallery').length)) {
$(this).after('<span class="caption">' + this.alt + '</span>');
}
// 对于已经包含在链接内的图片不适用lightGallery
if ($(this).parent().prop("tagName") !== 'A') {
$(this).wrap('<a href="' + ($(this).attr("data-imgbig") ? $(this).attr("data-imgbig") : this.src) + '" title="' + this.alt + '" class="gallery-item"></a>');
}
});
});
if (typeof lightGallery != 'undefined') {
var options = {
selector: '.gallery-item'
};
$('.article-entry').each(function(i, entry) {
lightGallery(entry, options);
});
lightGallery($('.article-gallery')[0], options);
}
if (!!$.prototype.justifiedGallery) { // if justifiedGallery method is defined
var options = {
rowHeight: 140,
margins: 4,
lastRow: 'justify'
};
$('.justified-gallery').justifiedGallery(options);
}
// Profile card
$(document).on('click', function () {
$('#profile').removeClass('card');
}).on('click', '#profile-anchor', function (e) {
e.stopPropagation();
$('#profile').toggleClass('card');
}).on('click', '.profile-inner', function (e) {
e.stopPropagation();
});
// To Top
if ($('#sidebar').length) {
$(document).on('scroll', function () {
if ($(document).width() >= 800) {
if(($(this).scrollTop() > toTop) && ($(this).scrollTop() > 0)) {
$('#toTop').fadeIn();
$('#toTop').css('left', $('#sidebar').offset().left);
} else {
$('#toTop').fadeOut();
}
} else {
$('#toTop').fadeIn();
$('#toTop').css('right', 20);
}
}).on('click', '#toTop', function () {
$('body, html').animate({ scrollTop: 0 }, 600);
});
}
})(jQuery);