440-change-direction.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Swiper demo</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. <!-- Link Swiper's CSS -->
  8. <link
  9. rel="stylesheet"
  10. href="../swiper-bundle.min.css"
  11. />
  12. <!-- Demo styles -->
  13. <style>
  14. html,
  15. body {
  16. position: relative;
  17. height: 100%;
  18. }
  19. body {
  20. background: #eee;
  21. font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  22. font-size: 14px;
  23. color: #000;
  24. margin: 0;
  25. padding: 0;
  26. }
  27. .swiper {
  28. width: 100%;
  29. height: 100%;
  30. }
  31. .swiper-slide {
  32. text-align: center;
  33. font-size: 18px;
  34. background: #fff;
  35. /* Center slide text vertically */
  36. display: -webkit-box;
  37. display: -ms-flexbox;
  38. display: -webkit-flex;
  39. display: flex;
  40. -webkit-box-pack: center;
  41. -ms-flex-pack: center;
  42. -webkit-justify-content: center;
  43. justify-content: center;
  44. -webkit-box-align: center;
  45. -ms-flex-align: center;
  46. -webkit-align-items: center;
  47. align-items: center;
  48. }
  49. @media (max-width: 760px) {
  50. .swiper-button-next {
  51. right: 20px;
  52. transform: rotate(90deg);
  53. }
  54. .swiper-button-prev {
  55. left: 20px;
  56. transform: rotate(90deg);
  57. }
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <!-- Swiper -->
  63. <div class="swiper">
  64. <div class="swiper-wrapper">
  65. <div class="swiper-slide">Resize me!</div>
  66. <div class="swiper-slide">Resize me!</div>
  67. <div class="swiper-slide">Resize me!</div>
  68. <div class="swiper-slide">Resize me!</div>
  69. <div class="swiper-slide">Resize me!</div>
  70. <div class="swiper-slide">Resize me!</div>
  71. <div class="swiper-slide">Resize me!</div>
  72. <div class="swiper-slide">Resize me!</div>
  73. <div class="swiper-slide">Resize me!</div>
  74. <div class="swiper-slide">Resize me!</div>
  75. </div>
  76. <div class="swiper-button-next"></div>
  77. <div class="swiper-button-prev"></div>
  78. </div>
  79. <!-- Swiper JS -->
  80. <script src="../swiper-bundle.min.js"></script>
  81. <!-- Initialize Swiper -->
  82. <script>
  83. var swiper = new Swiper('.swiper', {
  84. slidesPerView: 3,
  85. direction: getDirection(),
  86. navigation: {
  87. nextEl: '.swiper-button-next',
  88. prevEl: '.swiper-button-prev',
  89. },
  90. on: {
  91. resize: function () {
  92. swiper.changeDirection(getDirection());
  93. },
  94. },
  95. });
  96. function getDirection() {
  97. var windowWidth = window.innerWidth;
  98. var direction = window.innerWidth <= 760 ? 'vertical' : 'horizontal';
  99. return direction;
  100. }
  101. </script>
  102. </body>
  103. </html>