carousel.dev.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. "use strict";
  2. /** layui-v2.5.6 MIT License By https://www.layui.com */
  3. ;
  4. layui.define("jquery", function (e) {
  5. "use strict";
  6. var i = layui.$,
  7. n = (layui.hint(), layui.device(), {
  8. config: {},
  9. set: function set(e) {
  10. var n = this;
  11. return n.config = i.extend({}, n.config, e), n;
  12. },
  13. on: function on(e, i) {
  14. return layui.onevent.call(this, t, e, i);
  15. }
  16. }),
  17. t = "carousel",
  18. a = "layui-this",
  19. l = ">*[carousel-item]>*",
  20. o = "layui-carousel-left",
  21. r = "layui-carousel-right",
  22. d = "layui-carousel-prev",
  23. s = "layui-carousel-next",
  24. u = "layui-carousel-arrow",
  25. c = "layui-carousel-ind",
  26. m = function m(e) {
  27. var t = this;
  28. t.config = i.extend({}, t.config, n.config, e), t.render();
  29. };
  30. m.prototype.config = {
  31. width: "600px",
  32. height: "280px",
  33. full: !1,
  34. arrow: "hover",
  35. indicator: "inside",
  36. autoplay: !0,
  37. interval: 3e3,
  38. anim: "",
  39. trigger: "click",
  40. index: 0
  41. }, m.prototype.render = function () {
  42. var e = this,
  43. n = e.config;
  44. n.elem = i(n.elem), n.elem[0] && (e.elemItem = n.elem.find(l), n.index < 0 && (n.index = 0), n.index >= e.elemItem.length && (n.index = e.elemItem.length - 1), n.interval < 800 && (n.interval = 800), n.full ? n.elem.css({
  45. position: "fixed",
  46. width: "100%",
  47. height: "100%",
  48. zIndex: 9999
  49. }) : n.elem.css({
  50. width: n.width,
  51. height: n.height
  52. }), n.elem.attr("lay-anim", n.anim), e.elemItem.eq(n.index).addClass(a), e.elemItem.length <= 1 || (e.indicator(), e.arrow(), e.autoplay(), e.events()));
  53. }, m.prototype.reload = function (e) {
  54. var n = this;
  55. clearInterval(n.timer), n.config = i.extend({}, n.config, e), n.render();
  56. }, m.prototype.prevIndex = function () {
  57. var e = this,
  58. i = e.config,
  59. n = i.index - 1;
  60. return n < 0 && (n = e.elemItem.length - 1), n;
  61. }, m.prototype.nextIndex = function () {
  62. var e = this,
  63. i = e.config,
  64. n = i.index + 1;
  65. return n >= e.elemItem.length && (n = 0), n;
  66. }, m.prototype.addIndex = function (e) {
  67. var i = this,
  68. n = i.config;
  69. e = e || 1, n.index = n.index + e, n.index >= i.elemItem.length && (n.index = 0);
  70. }, m.prototype.subIndex = function (e) {
  71. var i = this,
  72. n = i.config;
  73. e = e || 1, n.index = n.index - e, n.index < 0 && (n.index = i.elemItem.length - 1);
  74. }, m.prototype.autoplay = function () {
  75. var e = this,
  76. i = e.config;
  77. i.autoplay && (clearInterval(e.timer), e.timer = setInterval(function () {
  78. e.slide();
  79. }, i.interval));
  80. }, m.prototype.arrow = function () {
  81. var e = this,
  82. n = e.config,
  83. t = i(['<button class="layui-icon ' + u + '" lay-type="sub">' + ("updown" === n.anim ? "&#xe619;" : "&#xe603;") + "</button>", '<button class="layui-icon ' + u + '" lay-type="add">' + ("updown" === n.anim ? "&#xe61a;" : "&#xe602;") + "</button>"].join(""));
  84. n.elem.attr("lay-arrow", n.arrow), n.elem.find("." + u)[0] && n.elem.find("." + u).remove(), n.elem.append(t), t.on("click", function () {
  85. var n = i(this),
  86. t = n.attr("lay-type");
  87. e.slide(t);
  88. });
  89. }, m.prototype.indicator = function () {
  90. var e = this,
  91. n = e.config,
  92. t = e.elemInd = i(['<div class="' + c + '"><ul>', function () {
  93. var i = [];
  94. return layui.each(e.elemItem, function (e) {
  95. i.push("<li" + (n.index === e ? ' class="layui-this"' : "") + "></li>");
  96. }), i.join("");
  97. }(), "</ul></div>"].join(""));
  98. n.elem.attr("lay-indicator", n.indicator), n.elem.find("." + c)[0] && n.elem.find("." + c).remove(), n.elem.append(t), "updown" === n.anim && t.css("margin-top", -(t.height() / 2)), t.find("li").on("hover" === n.trigger ? "mouseover" : n.trigger, function () {
  99. var t = i(this),
  100. a = t.index();
  101. a > n.index ? e.slide("add", a - n.index) : a < n.index && e.slide("sub", n.index - a);
  102. });
  103. }, m.prototype.slide = function (e, i) {
  104. var n = this,
  105. l = n.elemItem,
  106. u = n.config,
  107. c = u.index,
  108. m = u.elem.attr("lay-filter");
  109. n.haveSlide || ("sub" === e ? (n.subIndex(i), l.eq(u.index).addClass(d), setTimeout(function () {
  110. l.eq(c).addClass(r), l.eq(u.index).addClass(r);
  111. }, 50)) : (n.addIndex(i), l.eq(u.index).addClass(s), setTimeout(function () {
  112. l.eq(c).addClass(o), l.eq(u.index).addClass(o);
  113. }, 50)), setTimeout(function () {
  114. l.removeClass(a + " " + d + " " + s + " " + o + " " + r), l.eq(u.index).addClass(a), n.haveSlide = !1;
  115. }, 300), n.elemInd.find("li").eq(u.index).addClass(a).siblings().removeClass(a), n.haveSlide = !0, layui.event.call(this, t, "change(" + m + ")", {
  116. index: u.index,
  117. prevIndex: c,
  118. item: l.eq(u.index)
  119. }));
  120. }, m.prototype.events = function () {
  121. var e = this,
  122. i = e.config;
  123. i.elem.data("haveEvents") || (i.elem.on("mouseenter", function () {
  124. clearInterval(e.timer);
  125. }).on("mouseleave", function () {
  126. e.autoplay();
  127. }), i.elem.data("haveEvents", !0));
  128. }, n.render = function (e) {
  129. var i = new m(e);
  130. return i;
  131. }, e(t, n);
  132. });