BannerPagination.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // styling
  2. import styles from './styles.module.scss';
  3. import {useState} from "react";
  4. const BannerPagination = ({pageCount,swiper}) => {
  5. const pages = Array.from({ length: pageCount }, (_, index) => index);
  6. const checkActive=(index)=>{
  7. if (swiper!=null){
  8. let activeIndex=swiper.realIndex;
  9. if (activeIndex>pageCount)activeIndex=activeIndex%pageCount;
  10. return activeIndex==index;
  11. }
  12. return false;
  13. }
  14. const changeIndex =(index)=>{
  15. // slideTo
  16. if (swiper!=null){
  17. if (swiper.realIndex!=index){
  18. swiper.slideTo(index);
  19. }
  20. }
  21. }
  22. return (
  23. <div className={`${styles.banner_pagination}`}>
  24. {
  25. pages.map((page,index)=>(
  26. <span onClick={()=>{
  27. changeIndex(index);
  28. }} key={index} className={`${checkActive(index)?styles.banner_pagination_dot_active:''}`}></span>
  29. ))
  30. }
  31. </div>
  32. );
  33. }
  34. export default BannerPagination