main.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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')) return;
  7. var alt = this.alt;
  8. if (alt) $(this).after('<span class="caption">' + alt + '</span>');
  9. $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
  10. });
  11. $(this).find('.fancybox').each(function(){
  12. $(this).attr('rel', 'article' + i);
  13. });
  14. });
  15. if ($.fancybox){
  16. $('.fancybox').fancybox();
  17. }
  18. // Profile card
  19. $(document).on('click', function () {
  20. $('#profile').removeClass('card');
  21. }).on('click', '#profile-anchor', function (e) {
  22. e.stopPropagation();
  23. $('#profile').toggleClass('card');
  24. }).on('click', '.profile-inner', function (e) {
  25. e.stopPropagation();
  26. });
  27. // To Top
  28. $(document).on('scroll', function () {
  29. if ($(document).width() >= 800) {
  30. if($(this).scrollTop() > toTop) {
  31. $('#toTop').addClass('fix');
  32. $('#toTop').css('left', $('#sidebar').offset().left);
  33. } else {
  34. $('#toTop').removeClass('fix');
  35. }
  36. } else {
  37. $('#toTop').addClass('fix');
  38. $('#toTop').css('right', 20);
  39. }
  40. }).on('click', '#toTop', function () {
  41. $(document).scrollTop(0);
  42. });
  43. })(jQuery);