Banner.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { css } from "@linaria/core";
  2. import { defineComponent, reactive, ref } from "vue";
  3. import { Swiper, SwiperSlide } from "swiper/vue";
  4. import { Autoplay } from "swiper";
  5. import "swiper/css";
  6. export default defineComponent({
  7. setup() {
  8. const state = reactive({
  9. active: 0,
  10. });
  11. const swiperRef = ref();
  12. const images = [
  13. {
  14. url: getImageUrl("banner/banner.png"),
  15. },
  16. {
  17. url: getImageUrl("banner/banner.png"),
  18. },
  19. ];
  20. const initSwiper = (swiper: any) => {
  21. swiperRef.value = swiper;
  22. };
  23. return () => (
  24. <div class={page}>
  25. <Swiper
  26. class={"banner_swiper"}
  27. modules={[Autoplay]}
  28. autoplay={{
  29. delay: 5000,
  30. disableOnInteraction: false,
  31. }}
  32. loop={true}
  33. onSwiper={initSwiper}
  34. onSlideChange={(e) => {
  35. state.active = e.realIndex;
  36. }}
  37. >
  38. {images.map((e) => {
  39. return (
  40. <SwiperSlide>
  41. <img src={e.url} />
  42. </SwiperSlide>
  43. );
  44. })}
  45. </Swiper>
  46. <div class={"swiper_prev"}>
  47. <img
  48. src={getImageUrl("botton_prev.png")}
  49. onClick={() => {
  50. swiperRef.value.slidePrev();
  51. }}
  52. />
  53. </div>
  54. <div class={"swiper_next"}>
  55. <img
  56. src={getImageUrl("botton_next.png")}
  57. onClick={() => {
  58. swiperRef.value.slideNext();
  59. }}
  60. />
  61. </div>
  62. <div class={"swiper_pagination"}>
  63. {images.length > 0 && (
  64. <div class={"page_dots_box"}>
  65. {images.map((_, i) => {
  66. return (
  67. <div
  68. class={["page_dot", state.active == i ? "active" : null]}
  69. onClick={() => {
  70. swiperRef.value.slideTo(i);
  71. }}
  72. ></div>
  73. );
  74. })}
  75. </div>
  76. )}
  77. </div>
  78. </div>
  79. );
  80. },
  81. });
  82. const page = css`
  83. position: relative;
  84. width: 100%;
  85. height: 600px;
  86. max-height: 600px;
  87. .banner_swiper {
  88. height: 100%;
  89. img {
  90. height: 100%;
  91. width: 100%;
  92. object-fit: cover;
  93. user-select: none;
  94. }
  95. }
  96. .swiper_prev,
  97. .swiper_next {
  98. position: absolute;
  99. top: 0;
  100. width: 66px;
  101. height: 100%;
  102. z-index: 2;
  103. display: inline-flex;
  104. align-items: center;
  105. &:hover {
  106. img {
  107. opacity: 1;
  108. }
  109. }
  110. img {
  111. width: 66px;
  112. height: 66px;
  113. object-fit: contain;
  114. opacity: 0;
  115. transition: all 0.3s ease-in-out;
  116. cursor: pointer;
  117. user-select: none;
  118. }
  119. }
  120. .swiper_prev {
  121. left: 0;
  122. }
  123. .swiper_next {
  124. right: 0;
  125. }
  126. .swiper_pagination {
  127. position: absolute;
  128. bottom: 12px;
  129. left: 0;
  130. width: 100%;
  131. z-index: 2;
  132. text-align: center;
  133. .page_dots_box {
  134. display: inline-block;
  135. padding: 6px 9px;
  136. border-radius: 30px;
  137. font-size: 0;
  138. background-color: rgba(0, 0, 0, 0.56);
  139. .page_dot {
  140. display: inline-block;
  141. width: 12px;
  142. height: 12px;
  143. margin: 0 4px;
  144. border-radius: 6px;
  145. background-color: rgba(255, 255, 255, 0.6);
  146. transition: all 0.3s ease-in-out;
  147. cursor: pointer;
  148. &.active {
  149. width: 24px;
  150. background-color: rgba(255, 255, 255, 1);
  151. }
  152. }
  153. }
  154. }
  155. `;