import React, { useEffect, useRef, useState } from 'react'; import { motion } from…
- User
import React, { useEffect, useRef, useState } from 'react'; import { motion } from 'framer-motion'; import OnScreen from '../hooks/OnScreen'; // Adjust the import path as necessary
const SectionContact = () => { const backgroundImage =
${process.env.PUBLIC_URL}/img/agency-04.png; const floatImage =${process.env.PUBLIC_URL}/img/agency-04b.png;const imageRef = useRef(null);// Reference for the background image const [dragConstraints, setDragConstraints] = useState({ left: 0, top: 0, right: 0, bottom: 0 }); const floatImageWidthPercentage = '80%'; const floatImageHeightPercentage = '80%'; // Use the OnScreen hook to determine if the section is visible const [ref, isVisible] = OnScreen(); useEffect(() => { const updateConstraints = () => { if (imageRef.current) { const imageRect = imageRef.current.getBoundingClientRect(); // Update drag constraints based on the background image size when visible setDragConstraints({ left: 0, top: 0, right: imageRect.width - parseFloat(floatImageWidthPercentage) * imageRect.width / 100, bottom: imageRect.height - parseFloat(floatImageHeightPercentage) * imageRect.height / 100 }); } }; if (isVisible) { // Trigger the update only when visible updateConstraints(); } }, [isVisible, floatImageWidthPercentage, floatImageHeightPercentage]); return ( <div className="contact-section container-fluid mb-4" ref={ref}> <div className="underlay"> <img src={backgroundImage} alt="Background" ref={imageRef}// Assign ref for background image style={{ width: '100%', height: 'auto', display: 'block' }} /> </div> <div className="overlay"> <motion.img src={floatImage} alt="Floating" draggable={false}// Prevent default drag behavior style={{ position: 'absolute', width: floatImageWidthPercentage, eight: floatImageHeightPercentage, pointerEvents: isVisible ? 'auto' : 'none',// Enable dragging when visible }} drag={isVisible}// Enable dragging based on visibility dragConstraints={isVisible ? dragConstraints : undefined}// Set constraints only when visible dragElastic={0.2} whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }} transition={{ type: 'spring', stiffness: 300, damping: 10 }} /> </div> </div> );};
export default SectionContact;
so the float img likes to go past the contact-section class due to being a container-fluid is their anyway to stop this? without changing the container-fluid? maybe another container?
- Assistant