zoom.min.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function(e) {
  2. function u(u) {
  3. function c() {
  4. function h(e) {
  5. e.show();
  6. n.removeClass("loading")
  7. }
  8. var t = e(this),
  9. r = parseInt(n.css("borderLeftWidth")),
  10. i = s - r * 2,
  11. u = o - r * 2,
  12. a = t.width(),
  13. f = t.height();
  14. if (a == n.width() && a <= i && f == n.height() && f <= u) {
  15. h(t);
  16. return
  17. }
  18. if (a > i || f > u) {
  19. var l = u < f ? u: f,
  20. c = i < a ? i: a;
  21. if (l / f <= c / a) {
  22. t.width(a * l / f);
  23. t.height(l)
  24. } else {
  25. t.width(c);
  26. t.height(f * c / a)
  27. }
  28. }
  29. n.animate({
  30. width: t.width(),
  31. height: t.height(),
  32. marginTop: -(t.height() / 2) - r,
  33. marginLeft: -(t.width() / 2) - r
  34. },
  35. 200,
  36. function() {
  37. h(t)
  38. })
  39. }
  40. if (u) u.preventDefault();
  41. var a = e(this),
  42. f = a.attr("href");
  43. if (!f) return;
  44. var l = e(new Image).hide();
  45. e("#zoom .previous, #zoom .next").show();
  46. if (a.hasClass("zoom")) e("#zoom .previous, #zoom .next").hide();
  47. if (!r) {
  48. r = true;
  49. t.show();
  50. e("body").addClass("zoomed")
  51. }
  52. n.html(l).delay(500).addClass("loading");
  53. l.load(c).attr("src", f);
  54. i = a
  55. }
  56. function a() {
  57. var t = i.parent("li").prev();
  58. if (t.length == 0) t = e(".gallery li:last-child");
  59. t.find("a").trigger("click")
  60. }
  61. function f() {
  62. var t = i.parent("li").next();
  63. if (t.length == 0) t = e(".gallery li:first-child");
  64. t.children("a").trigger("click")
  65. }
  66. function l(s) {
  67. if (s) s.preventDefault();
  68. r = false;
  69. i = null;
  70. t.hide();
  71. e("body").removeClass("zoomed");
  72. n.empty()
  73. }
  74. function c() {
  75. s = e(window).width();
  76. o = e(window).height()
  77. }
  78. e("body").append('<div id="zoom"><a class="close"></a><a href="#previous" class="previous"></a><a href="#next" class="next"></a><div class="content loading"></div></div>');
  79. var t = e("#zoom").hide(),
  80. n = e("#zoom .content"),
  81. r = false,
  82. i = null,
  83. s = e(window).width(),
  84. o = e(window).height(); (function() {
  85. t.on("click",
  86. function(t) {
  87. t.preventDefault();
  88. if (e(t.target).attr("id") == "zoom") l()
  89. });
  90. e("#zoom .close").on("click", l);
  91. e("#zoom .previous").on("click", a);
  92. e("#zoom .next").on("click", f);
  93. e(document).keydown(function(e) {
  94. if (!i) return;
  95. if (e.which == 38 || e.which == 40) e.preventDefault();
  96. if (e.which == 27) l();
  97. if (e.which == 37 && !i.hasClass("zoom")) a();
  98. if (e.which == 39 && !i.hasClass("zoom")) f()
  99. });
  100. if (e(".gallery li a").length == 1) e(".gallery li a:first").addClass("zoom");
  101. e(".zoom, .gallery li a").on("click", u)
  102. })(); (function() {
  103. e(window).on("resize", c)
  104. })(); (function() {
  105. e(window).on("mousewheel DOMMouseScroll",
  106. function(e) {
  107. if (!i) return;
  108. e.stopPropagation();
  109. e.preventDefault();
  110. e.cancelBubble = false
  111. })
  112. })()
  113. })(jQuery);