290-manipulation.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. .swiper-slide img {
  53. display: block;
  54. width: 100%;
  55. height: 100%;
  56. object-fit: cover;
  57. }
  58. .swiper {
  59. width: 100%;
  60. height: 300px;
  61. margin: 20px auto;
  62. }
  63. .append-buttons {
  64. text-align: center;
  65. margin-top: 20px;
  66. }
  67. .append-buttons button {
  68. display: inline-block;
  69. cursor: pointer;
  70. border: 1px solid #007aff;
  71. color: #007aff;
  72. text-decoration: none;
  73. padding: 4px 10px;
  74. border-radius: 4px;
  75. margin: 0 10px;
  76. font-size: 13px;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <!-- Swiper -->
  82. <div #swiperRef="" class="swiper mySwiper">
  83. <div class="swiper-wrapper">
  84. <div class="swiper-slide">Slide 1</div>
  85. <div class="swiper-slide">Slide 2</div>
  86. <div class="swiper-slide">Slide 3</div>
  87. <div class="swiper-slide">Slide 4</div>
  88. </div>
  89. <div class="swiper-button-next"></div>
  90. <div class="swiper-button-prev"></div>
  91. <div class="swiper-pagination"></div>
  92. </div>
  93. <p class="append-buttons">
  94. <button class="prepend-2-slides">Prepend 2 Slides</button>
  95. <button class="prepend-slide">Prepend Slide</button>
  96. <button class="append-slide">Append Slide</button>
  97. <button class="append-2-slides">Append 2 Slides</button>
  98. </p>
  99. <!-- Swiper JS -->
  100. <script src="../swiper-bundle.min.js"></script>
  101. <!-- Initialize Swiper -->
  102. <script>
  103. var swiper = new Swiper(".mySwiper", {
  104. slidesPerView: 3,
  105. centeredSlides: true,
  106. spaceBetween: 30,
  107. pagination: {
  108. el: ".swiper-pagination",
  109. type: "fraction",
  110. },
  111. navigation: {
  112. nextEl: ".swiper-button-next",
  113. prevEl: ".swiper-button-prev",
  114. },
  115. });
  116. var appendNumber = 4;
  117. var prependNumber = 1;
  118. document
  119. .querySelector(".prepend-2-slides")
  120. .addEventListener("click", function (e) {
  121. e.preventDefault();
  122. swiper.prependSlide([
  123. '<div class="swiper-slide">Slide ' + --prependNumber + "</div>",
  124. '<div class="swiper-slide">Slide ' + --prependNumber + "</div>",
  125. ]);
  126. });
  127. document
  128. .querySelector(".prepend-slide")
  129. .addEventListener("click", function (e) {
  130. e.preventDefault();
  131. swiper.prependSlide(
  132. '<div class="swiper-slide">Slide ' + --prependNumber + "</div>"
  133. );
  134. });
  135. document
  136. .querySelector(".append-slide")
  137. .addEventListener("click", function (e) {
  138. e.preventDefault();
  139. swiper.appendSlide(
  140. '<div class="swiper-slide">Slide ' + ++appendNumber + "</div>"
  141. );
  142. });
  143. document
  144. .querySelector(".append-2-slides")
  145. .addEventListener("click", function (e) {
  146. e.preventDefault();
  147. swiper.appendSlide([
  148. '<div class="swiper-slide">Slide ' + ++appendNumber + "</div>",
  149. '<div class="swiper-slide">Slide ' + ++appendNumber + "</div>",
  150. ]);
  151. });
  152. </script>
  153. </body>
  154. </html>