永城市12345 (县级市)- 来源于虞城县12345 - 所有县级统一API

pageSwitch.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ! function(t) {
  2. var e = function(t) {
  3. var e = ["webkit", "Moz", "o", "ms"],
  4. n = "";
  5. for(var i in e)
  6. if(n = e[i] + "Transition", void 0 !== t.style[n]) return "-" + e[i].toLowerCase() + "-"
  7. }(document.createElement(n)),
  8. n = function() {
  9. function n(e, n) {
  10. this.settings = t.extend(!0, t.fn.PageSwitch.defaults, n || {}), this.element = e, this.init()
  11. }
  12. return n.prototype = {
  13. init: function() {
  14. var t = this;
  15. t.selectors = t.settings.selectors, t.sections = t.element.find(t.selectors.sections), t.section = t.element.find(t.selectors.section), t.direction = "vertical" == t.settings.direction, t.pagesCount = t.getPagesCount(), t.index = t.settings.index >= 0 && t.settings.index < t.pagesCount ? t.settings.index : 0, t.canScroll = !0, t.direction || t._initLayout(), t.settings.autoPlay && (t.settings.loop = !0, t.timer = null, t._autoPlay()), t.settings.pagination && t._initPaging()
  16. },
  17. getPagesCount: function() {
  18. return this.section.length
  19. },
  20. switchLength: function() {
  21. return this.direction ? this.element.height() : this.element.width()
  22. },
  23. _autoPlay: function() {
  24. function t() {
  25. e.timer = setTimeout(function() {
  26. e.next(), t()
  27. }, e.settings.interval)
  28. }
  29. var e = this;
  30. t()
  31. },
  32. _stopPlay: function() {
  33. clearTimeout(this.timer)
  34. },
  35. _initLayout: function() {
  36. var t = this,
  37. e = 100 * t.pagesCount + "%",
  38. n = (100 / t.pagesCount).toFixed(2) + "%";
  39. t.sections.width(e), t.section.width(n).css("float", "left")
  40. },
  41. _initPaging: function() {
  42. var t = this,
  43. e = t.selectors.pages.substring(1);
  44. t.activeClass = t.selectors.active.substring(1);
  45. for(var n = "<ul class='" + e + "'>", i = 0; i < t.pagesCount; i++) n += "<li></li>";
  46. n += "</ul>", t.element.append(n);
  47. var s = t.element.find(t.selectors.pages);
  48. t.pageItem = s.find("li"), t.pageItem.eq(t.index).addClass(t.activeClass), t.direction ? s.addClass("vertical") : s.addClass("horizontal"), t._initEvent()
  49. },
  50. _initEvent: function() {
  51. var e = this;
  52. e.element.on("click", e.selectors.pages + " li", function() {
  53. e.index = t(this).index(), e._scrollPage()
  54. }), e.settings.autoPlay && (e.element.on("mouseover", e.selectors.pages + " li", function() {
  55. e._stopPlay()
  56. }), e.element.on("mouseout", e.selectors.pages + " li", function() {
  57. e._autoPlay()
  58. })), e.element.on("mousewheel DOMMouseScroll", function(t) {
  59. if(e.canScroll) {
  60. var n = t.originalEvent.wheelDelta || -t.originalEvent.detail;
  61. n > 0 && (e.index && !e.settings.loop || e.settings.loop) ? e.prev() : n < 0 && (e.index < e.pagesCount - 1 && !e.settings.loop || e.settings.loop) && e.next()
  62. }
  63. }), e.settings.keyboard && t(window).on("keydown", function(t) {
  64. var n = t.keyCode;
  65. 37 == n || 38 == n ? e.prev() : 39 != n && 40 != n || e.next()
  66. }), t(window).resize(function() {
  67. var t = e.switchLength(),
  68. n = e.settings.direction ? e.section.eq(e.index).offset().top : e.section.eq(e.index).offset().left;
  69. Math.abs(n) > t / 2 && e.index < e.pagesCount - 1 && e.index++, e.index && e._scrollPage()
  70. }), e.sections.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend", function() {
  71. e.canScroll = !0, e.settings.callback && "function" === t.type(e.settings.callback) && e.settings.callback(e.index)
  72. })
  73. },
  74. prev: function() {
  75. var t = this;
  76. t.index > 0 ? t.index-- : t.settings.loop && (t.index = t.pagesCount - 1), t._scrollPage()
  77. },
  78. next: function() {
  79. var t = this;
  80. t.index < t.pagesCount - 1 ? t.index++ : t.settings.loop && (t.index = 0), t._scrollPage()
  81. },
  82. _scrollPage: function() {
  83. var n = this,
  84. i = n.section.eq(n.index).position(),
  85. s = n.section.eq(n.index).innerWidth(),
  86. o = n.section.eq(n.index).innerHeight(),
  87. a = n.sections.innerWidth(),
  88. c = n.sections.innerHeight();
  89. if("continuous" === n.settings.scrollType && 0 !== n.index && (n.direction && o < c && (i.top = n.section.eq(n.index - 1).position().top + o), !n.direction && s < a && (i.left = n.section.eq(n.index - 1).position().left + s)), i) {
  90. if(n.canScroll = !1, e) {
  91. n.sections.css(e + "transition", "all " + n.settings.duration + "ms " + n.settings.easing);
  92. var l = n.direction ? "translateY(-" + i.top + "px)" : "translateX(-" + i.left + "px)";
  93. n.sections.css(e + "transform", l)
  94. } else {
  95. var r = n.direction ? {
  96. top: -i.top
  97. } : {
  98. left: -i.left
  99. };
  100. n.sections.animate(r, n.settings.duration, function() {
  101. n.canScroll = !0, n.settings.callback && "function" === t.type(n.settings.callback) && n.settings.callback()
  102. })
  103. }
  104. n.settings.pagination && n.pageItem.eq(n.index).addClass(n.activeClass).siblings("li").removeClass(n.activeClass)
  105. }
  106. }
  107. }, n
  108. }();
  109. t.fn.PageSwitch = function(e) {
  110. return this.each(function() {
  111. var i = t(this),
  112. s = i.data("PageSwitch");
  113. if(s || (s = new n(i, e), i.data("PageSwitch", s)), "string" === t.type(e)) return s[e]()
  114. })
  115. }, t.fn.PageSwitch.defaults = {
  116. selectors: {
  117. sections: ".sections",
  118. section: ".section",
  119. pages: ".pages",
  120. active: ".active"
  121. },
  122. index: 0,
  123. easing: "ease",
  124. duration: 500,
  125. loop: !1,
  126. pagination: !0,
  127. keyboard: !0,
  128. direction: "vertical",
  129. autoPlay: !0,
  130. interval: 3e3,
  131. scrollType: "fullPage",
  132. callback: ""
  133. }, t(function() {
  134. t("[data-PageSwitch]").PageSwitch()
  135. })
  136. }(jQuery);