main.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function($){
  2. var toTop = $('#toTop').length ? $('#toTop').offset().top - $(window).height() + 20 : 0;
  3. // Caption
  4. $('.article-entry').each(function(i){
  5. $(this).find('img').each(function(){
  6. if ($(this).parent().hasClass('fancybox')) {
  7. return;
  8. }
  9. var alt = this.alt;
  10. if (alt) {
  11. $(this).after('<span class="caption">' + alt + '</span>');
  12. }
  13. $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
  14. });
  15. $(this).find('.fancybox').each(function(){
  16. $(this).attr('rel', 'article' + i);
  17. });
  18. });
  19. if ($.fancybox){
  20. $('.fancybox').fancybox();
  21. }
  22. // Profile card
  23. $(document).on('click', function () {
  24. $('#profile').removeClass('card');
  25. }).on('click', '#profile-anchor', function (e) {
  26. e.stopPropagation();
  27. $('#profile').toggleClass('card');
  28. }).on('click', '.profile-inner', function (e) {
  29. e.stopPropagation();
  30. });
  31. // To Top
  32. $(document).on('scroll', function () {
  33. if ($(document).width() >= 800) {
  34. if($(this).scrollTop() > toTop) {
  35. $('#toTop').addClass('fix');
  36. $('#toTop').css('left', $('#sidebar').offset().left);
  37. } else {
  38. $('#toTop').removeClass('fix');
  39. }
  40. } else {
  41. $('#toTop').addClass('fix');
  42. $('#toTop').css('right', 20);
  43. }
  44. }).on('click', '#toTop', function () {
  45. $('body, html').animate({ scrollTop: 0 }, 600);
  46. });
  47. })(jQuery);