420-custom-plugin.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Swiper demo</title>
  6. <meta
  7. name="viewport"
  8. content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"
  9. />
  10. <!-- Link Swiper's CSS -->
  11. <link
  12. rel="stylesheet"
  13. href="../swiper-bundle.min.css"
  14. />
  15. <!-- Demo styles -->
  16. <style>
  17. html,
  18. body {
  19. position: relative;
  20. height: 100%;
  21. }
  22. body {
  23. background: #eee;
  24. font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  25. font-size: 14px;
  26. color: #000;
  27. margin: 0;
  28. padding: 0;
  29. }
  30. .swiper {
  31. width: 100%;
  32. height: 100%;
  33. }
  34. .swiper-slide {
  35. text-align: center;
  36. font-size: 18px;
  37. background: #fff;
  38. /* Center slide text vertically */
  39. display: -webkit-box;
  40. display: -ms-flexbox;
  41. display: -webkit-flex;
  42. display: flex;
  43. -webkit-box-pack: center;
  44. -ms-flex-pack: center;
  45. -webkit-justify-content: center;
  46. justify-content: center;
  47. -webkit-box-align: center;
  48. -ms-flex-align: center;
  49. -webkit-align-items: center;
  50. align-items: center;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <!-- Swiper -->
  56. <div class="swiper">
  57. <div class="swiper-wrapper">
  58. <div class="swiper-slide">Slide 1</div>
  59. <div class="swiper-slide">Slide 2</div>
  60. <div class="swiper-slide">Slide 3</div>
  61. <div class="swiper-slide">Slide 4</div>
  62. <div class="swiper-slide">Slide 5</div>
  63. <div class="swiper-slide">Slide 6</div>
  64. <div class="swiper-slide">Slide 7</div>
  65. <div class="swiper-slide">Slide 8</div>
  66. <div class="swiper-slide">Slide 9</div>
  67. <div class="swiper-slide">Slide 10</div>
  68. </div>
  69. <!-- Add Pagination -->
  70. <div class="swiper-pagination"></div>
  71. <!-- Add Navigation -->
  72. <div class="swiper-button-prev"></div>
  73. <div class="swiper-button-next"></div>
  74. </div>
  75. <!-- Swiper JS -->
  76. <script src="../swiper-bundle.min.js"></script>
  77. <!-- Include plugin after Swiper -->
  78. <script>
  79. /* ========
  80. Debugger plugin, simple demo plugin to console.log some of callbacks
  81. ======== */
  82. function myPlugin({ swiper, extendParams, on }) {
  83. extendParams({
  84. debugger: false,
  85. });
  86. on('init', () => {
  87. if (!swiper.params.debugger) return;
  88. console.log('init');
  89. });
  90. on('click', (swiper, e) => {
  91. if (!swiper.params.debugger) return;
  92. console.log('click');
  93. });
  94. on('tap', (swiper, e) => {
  95. if (!swiper.params.debugger) return;
  96. console.log('tap');
  97. });
  98. on('doubleTap', (swiper, e) => {
  99. if (!swiper.params.debugger) return;
  100. console.log('doubleTap');
  101. });
  102. on('sliderMove', (swiper, e) => {
  103. if (!swiper.params.debugger) return;
  104. console.log('sliderMove');
  105. });
  106. on('slideChange', () => {
  107. if (!swiper.params.debugger) return;
  108. console.log(
  109. 'slideChange',
  110. swiper.previousIndex,
  111. '->',
  112. swiper.activeIndex
  113. );
  114. });
  115. on('slideChangeTransitionStart', () => {
  116. if (!swiper.params.debugger) return;
  117. console.log('slideChangeTransitionStart');
  118. });
  119. on('slideChangeTransitionEnd', () => {
  120. if (!swiper.params.debugger) return;
  121. console.log('slideChangeTransitionEnd');
  122. });
  123. on('transitionStart', () => {
  124. if (!swiper.params.debugger) return;
  125. console.log('transitionStart');
  126. });
  127. on('transitionEnd', () => {
  128. if (!swiper.params.debugger) return;
  129. console.log('transitionEnd');
  130. });
  131. on('fromEdge', () => {
  132. if (!swiper.params.debugger) return;
  133. console.log('fromEdge');
  134. });
  135. on('reachBeginning', () => {
  136. if (!swiper.params.debugger) return;
  137. console.log('reachBeginning');
  138. });
  139. on('reachEnd', () => {
  140. if (!swiper.params.debugger) return;
  141. console.log('reachEnd');
  142. });
  143. }
  144. </script>
  145. <script>
  146. // Init Swiper
  147. var swiper = new Swiper('.swiper', {
  148. // Install Plugin To Swiper
  149. modules: [myPlugin],
  150. pagination: {
  151. el: '.swiper-pagination',
  152. clickable: true,
  153. },
  154. navigation: {
  155. nextEl: '.swiper-button-next',
  156. prevEl: '.swiper-button-prev',
  157. },
  158. // Enable debugger
  159. debugger: true,
  160. });
  161. </script>
  162. </body>
  163. </html>