Clientele.js
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useRef, useEffect, useState } from "react";
import Image from "next/image";
import { cleanImage } from "@/layout/imageHandling";
const Clientele = ({ partners = [], itemClassName = "single-partner-item" }) => {
  const trackRef = useRef(null);
  const [animationDuration, setAnimationDuration] = useState(120);
  useEffect(() => {
    if (trackRef.current) {
      const trackWidth = trackRef.current.scrollWidth;
      const baseSpeed = 100; // pixels per second
      const duration = trackWidth / baseSpeed; // calculate duration dynamically
      setAnimationDuration(duration);
    }
  }, [partners]);
  return (
    <div className="partner-area py-4 overflow-hidden">
      <div className="container">
        <div className="marquee-wrapper position-relative">
          <div
            className="marquee-track d-flex"
            ref={trackRef}
            style={{ animationDuration: `${animationDuration}s` }}
          >
            {partners.concat(partners).map((logo, index) => (
              <div
                className={`${itemClassName} d-flex justify-content-center align-items-center `}
                key={`${logo.id}-${index}`}
                style={{ flex: "0 0 auto", width: "300px", height: "80px" }}
              >
                <Image
                  alt={logo?.logos[0]?.alternativeText || "image"}
                  src={cleanImage(logo?.logos[0]?.url)}
                  width={120}
                  height={60}
                  className="img-fluid industry-logo"
                />
              </div>
            ))}
          </div>
        </div>
      </div>
      <style jsx>{`
        .marquee-wrapper {
          width: 100%;
          overflow: hidden;
          position: relative;
        }
        .marquee-track {
          display: flex;
          width: max-content;
          animation: scroll-left linear infinite;
        }
        @keyframes scroll-left {
          0% {
            transform: translateX(0%);
          }
          100% {
            transform: translateX(-50%);
          }
        }
      `}</style>
    </div>
  );
};
export default Clientele;