mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 03:49:45 +00:00
анимация в каруселе, фикс навбара, выравнивание контактной формы
This commit is contained in:
1 parent
1f400b782c
commit
8dc93a67b9
11 files changed
+110
-40
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useState, useRef } from 'react';
|
||||
import { Swiper, SwiperSlide } from 'swiper/react';
|
||||
import { Navigation, Pagination } from 'swiper/modules';
|
||||
|
||||
@@ -9,11 +9,15 @@ import 'swiper/css/pagination';
|
||||
import { getMedia } from '../../api';
|
||||
import './Slider.styles.scss';
|
||||
|
||||
import arrow from "../../assets/images/arrow.svg";
|
||||
|
||||
function Slider({ autoPlay = false, autoPlayTime = 3000, images = false, variant = "default" }) {
|
||||
const [mediaList, setMediaList] = useState([]);
|
||||
const [itemsPerSlide, setItemsPerSlide] = useState(window.innerWidth <= 768 ? 1 : 2);
|
||||
const [enableButtons, setEnableButtons] = useState(false);
|
||||
|
||||
const swiperRef = useRef(null); // для кнопок
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setItemsPerSlide(window.innerWidth <= 768 ? 1 : 2);
|
||||
@@ -38,8 +42,20 @@ function Slider({ autoPlay = false, autoPlayTime = 3000, images = false, variant
|
||||
// Фиксим центрирование 1 слайда
|
||||
const slidesView = mediaList.length === 1 ? 1 : (variant === "news" ? (window.innerWidth <= 768 ? 1 : 1.4) : itemsPerSlide);
|
||||
|
||||
return (
|
||||
<div className={`slider ${variant}`}>
|
||||
// Проверяем, сколько изображений, чтобы отключить анимацию для 2 или менее изображений
|
||||
const sliderClass = mediaList.length <= 2 && variant === 'news' ? 'no-animation' : '';
|
||||
|
||||
|
||||
return (
|
||||
<div className={`slider ${variant} ${sliderClass}`}>
|
||||
{/* Кастомные стрелки */}
|
||||
{enableButtons && (
|
||||
<div className="custom-navigation">
|
||||
<button className="custom-prev" onClick={() => swiperRef.current?.slidePrev()}><img src={arrow} alt="prev"/></button>
|
||||
<button className="custom-next" onClick={() => swiperRef.current?.slideNext()}><img src={arrow} alt="next" style={{ transform: "rotate(180deg)" }}/></button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Swiper
|
||||
modules={[Navigation, Pagination]}
|
||||
spaceBetween={variant === "news" ? 20 : 30}
|
||||
@@ -47,9 +63,9 @@ function Slider({ autoPlay = false, autoPlayTime = 3000, images = false, variant
|
||||
centeredSlides={mediaList.length === 1 ? false : variant === "news"}
|
||||
slidesPerGroup={1}
|
||||
loop={enableButtons}
|
||||
navigation={enableButtons}
|
||||
pagination={{ clickable: enableButtons }}
|
||||
autoplay={autoPlay ? { delay: autoPlayTime, disableOnInteraction: false } : false}
|
||||
onSwiper={(swiper) => (swiperRef.current = swiper)} // Связываем Swiper с ref
|
||||
>
|
||||
{mediaList.map((media, index) => (
|
||||
<SwiperSlide key={media.id} className={mediaList.length === 1 ? 'swiper-slide single' : 'swiper-slide'}>
|
||||
|
||||
Reference in new issue
Block a user