|
|
|
@ -3,42 +3,57 @@ import _ from "lodash"; |
|
|
|
|
import scroll from "../../../utils/scroll"; |
|
|
|
|
|
|
|
|
|
export default function Page2({ list, page }) { |
|
|
|
|
const height = window.innerHeight; |
|
|
|
|
const [top, setTop] = useState(window.innerHeight); |
|
|
|
|
const [boxPosition, setBoxPosition] = useState({ |
|
|
|
|
translateX : -12, |
|
|
|
|
translateY : 5, |
|
|
|
|
rotate : 5, |
|
|
|
|
translateY: null, |
|
|
|
|
translateX: null, |
|
|
|
|
rotate: null, |
|
|
|
|
}); |
|
|
|
|
useEffect(() => { |
|
|
|
|
setBoxPosition({ |
|
|
|
|
translateY: boxPositionFormula(window.scrollY, 5, 7, "increase"), |
|
|
|
|
translateX: boxPositionFormula(window.scrollY, 5, 7, "increase"), |
|
|
|
|
rotate: boxPositionFormula(window.scrollY, 5, 10, "decrease"), |
|
|
|
|
}); |
|
|
|
|
window.addEventListener("scroll", (e) => { |
|
|
|
|
setTop(scroll.homeScrollHandler(page)); |
|
|
|
|
boxPositionHandler(window.scrollY); |
|
|
|
|
mobilePositionHandler(window.scrollY); |
|
|
|
|
}); |
|
|
|
|
}, []); |
|
|
|
|
const height = window.innerHeight; |
|
|
|
|
|
|
|
|
|
const boxPositionHandler = (scrollY) => { |
|
|
|
|
if(scrollY <= height){ |
|
|
|
|
setBoxPosition({ |
|
|
|
|
translateY : 5, |
|
|
|
|
translateX : -12, |
|
|
|
|
rotate : 5, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (scrollY > height && scrollY <= 2 * height) { |
|
|
|
|
if (scrollY <= height) { |
|
|
|
|
setBoxPosition({ |
|
|
|
|
translateY : (-9 + (scrollY + height) / 154) > 12 ? 12 : (-9 + (scrollY + height) / 154), |
|
|
|
|
translateX : (-66 + (scrollY + height) / 40) > 15 ? 15 : (-66 + (scrollY + height) / 40), |
|
|
|
|
rotate : (-((scrollY + height) / 214) + 15) < 0 ? 0 : (-((scrollY + height) / 214) + 15), |
|
|
|
|
translateY: 5, |
|
|
|
|
translateX: -12, |
|
|
|
|
rotate: 5, |
|
|
|
|
}); |
|
|
|
|
}else{ |
|
|
|
|
} else if (scrollY > height && scrollY <= 2 * height) { |
|
|
|
|
setBoxPosition({ |
|
|
|
|
translateY : 12, |
|
|
|
|
translateX : 15, |
|
|
|
|
rotate : 0, |
|
|
|
|
...boxPosition, |
|
|
|
|
translateY: boxPositionFormula(scrollY, 5, 7, "increase"), |
|
|
|
|
translateX: boxPositionFormula(scrollY, -12, 1.5, "increase"), |
|
|
|
|
rotate: boxPositionFormula(scrollY, 5, 10, "decrease"), |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// setBoxPosition({
|
|
|
|
|
// translateY: 12,
|
|
|
|
|
// translateX: 15,
|
|
|
|
|
// rotate: 0,
|
|
|
|
|
// });
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const mobilePositionHandler = (scrollY) => {}; |
|
|
|
|
|
|
|
|
|
const boxPositionFormula = (scrollY, first, speed, direction) => { |
|
|
|
|
if (direction === "increase") { |
|
|
|
|
return first + (((scrollY - height) / scrollY) * 100) / speed; |
|
|
|
|
} else { |
|
|
|
|
return first - (((scrollY - height) / scrollY) * 100) / speed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
return ( |
|
|
|
|
<div |
|
|
|
@ -47,11 +62,17 @@ export default function Page2({ list, page }) { |
|
|
|
|
> |
|
|
|
|
<div |
|
|
|
|
className={_.join( |
|
|
|
|
["relative w-full h-full bg-blue-500 shadow-2xl transform"], |
|
|
|
|
[ |
|
|
|
|
"relative w-full h-full shadow-2xl transform d-flex justify-center bg-white items-center text-center", |
|
|
|
|
], |
|
|
|
|
" " |
|
|
|
|
)} |
|
|
|
|
style={{ transform: `translateX(${boxPosition.translateX}%) rotate(${boxPosition.rotate}deg) translateY(${boxPosition.translateY}%)` }} |
|
|
|
|
></div> |
|
|
|
|
style={{ |
|
|
|
|
transform: `translateX(${boxPosition.translateX}%) rotate(${boxPosition.rotate}deg) translateY(${boxPosition.translateY}%)`, |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
<div className="absolute left-4 top-4 h-40 w-40 bg-red-500"></div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|