// turtle_co/src/App.js
import React, { useEffect, useState } from 'react';
import './App.css';
function App() {
const [scrollPosition, setScrollPosition] = useState(0);
useEffect(() => {
const handleScroll = () => {
setScrollPosition(window.scrollY);
};
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
// Calculate the initial transform value to center the text
const initialTransform = `translateX(-${scrollPosition / 2}px)`;
return (
<div className="App">
<header className="App-header">
<h1>App-header</h1>
</header>
<h1 style={{ transform: initialTransform }}>안녕,</h1>
</div>
);
}
export default App;
/* turtle_co/src/App.css */
.App {
text-align: center;
height: 3000px;
}
.App-header {
background-color: #282c34;
padding: 3px;
margin-left: 100px;
margin-right: 100px;
color: white;
font-size: 10px;
}
728x90
'Programming > React' 카테고리의 다른 글
버튼 누르면 알림권한 요청 (0) | 2024.02.13 |
---|---|
스크롤에 따라 360도 돌아가게 (0) | 2024.01.30 |
리액트 componenet 만들기 : <div>가 많으면 component 사용 (1) | 2024.01.16 |
React 좋아요 누를때마다 1씩 증가하는 버튼 만들기 (0) | 2024.01.16 |
리액트 Button을 누르면 state 변경 값으로 전환 *원본 데이터 보존 (0) | 2024.01.16 |