티스토리 뷰
728x90
반응형
스크롤의 위치에 따라 실행되는 애니메이션을 만들어볼건데요~
스크롤 이벤트라고 하죠?
스크롤을 내릴 때마다 svg애니메이션이 돌아가게 하는 결과물이구요
svg애니메이션은 나중에 또 따로 포스팅을 하기로 해요
실은 순서대로 하는게 맞는데 그러다보니 자꾸 밀려서;;;
동영상 서비스가 종료되어 해당 콘텐츠를 재생할 수 없습니다.
일단 html구조 자체를 한섹션씩 짜버리게 했습니다.

이미지 + 텍스트박스 + cass svg 를 한 박스로 묶어서 네개를 만들고
svg는 absolute처리를 했구요
// SVG HTML
<svg width=520 height=220 class="name2">
<text x="0" y="50%">h</text>
<text x="90" y="50%">a</text>
<text x="170" y="50%">n</text>
<text x="265" y="50%">m</text>
<text x="400" y="50%">a</text>
<text x="470" y="50%">c</text>
</svg>
// SVG CSS
/*svg*/
@keyframes stroke {
0% {
stroke:#fff;
stroke-width: 1px;
stroke-dashoffset: 326px;
}
70% {
fill: transparent;
}
98% {
stroke:#fff;
stroke-width: 1px;
}
100% {
fill: rgba(255, 255, 255, 0.2);
stroke-dashoffset: 0px;
}
}
svg {
position:absolute;
z-index: 5;
}
svg.name1 {
top: 80px;
left: 50px;
}
svg.name2 {
top: 25%;
right: 6px;
}
svg.name3 {
bottom: 40%;
left: 20px;
}
svg.name4 {
bottom: -30px;
right: -27px;
}
svg text {
font-family: 'Roboto Serif', serif;
font-size: 14rem;
fill: transparent;
stroke-dasharray: 326px;
}
svg.on text {
animation: stroke 1s linear;
animation-fill-mode: forwards;
}
svg:first-child text {
font-size: 15rem;
}
svg text:nth-child(1) {
animation-delay: 0s;
}
svg text:nth-child(2) {
animation-delay: 0.5s;
}
svg text:nth-child(3) {
animation-delay: 1s;
}
svg text:nth-child(4) {
animation-delay: 1.5s;
}
svg text:nth-child(5) {
animation-delay: 2s;
}
svg text:nth-child(6) {
animation-delay: 2.5s;
}
svg text:nth-child(7) {
animation-delay: 3s;
}
const content = document.querySelectorAll('.brand-list > ul')
//scrollHnadler 함수 실행
function scrollHandler() {
// content배열의 각 요소에 대한 반복문 실행
content.forEach((el) => {
// 변수에 현재 반복중인 요소를 할당
const offsetEle = el
// 변수에 현재 요소의 상단에서 부모 요소까지의 거리를 할당
const offsetTop = el.offsetTop
// 변수에 현재 윈도우의 수직 스크롤 위치를 할당
const scrollY = window.scrollY
console.log(offsetEle, offsetTop, scrollY)
// 스크롤 위치가 offsetTop보다 크면 실행하는 조건식
if (scrollY > offsetTop) {
// el요소의 자식 중에 svg요소를 찾아 변수 할당
const offsetEleChild = el.querySelector('svg');
// iffsetEleChild 존재한다면 코드 실행
if (offsetEleChild) {
offsetEleChild.classList.add('on');
}
}
});
}
window.addEventListener('scroll', scrollHandler)
728x90
반응형
'WEB > JS코드' 카테고리의 다른 글
| mousemove) 마우스 커서 따라다니는 효과 (0) | 2023.06.30 |
|---|---|
| JS) 숫자 카운트 setInterval(), setTimeout(), toLocaleString(); (0) | 2023.06.28 |
| JS) 타이핑하며 나오는 텍스트효과 (0) | 2023.06.09 |
| JS) Array.from()을 이용, html요소의 index값을 받아보자 (0) | 2023.06.08 |
| JS) 숫자 카운트 setInterval(), setTimeout() (0) | 2023.06.07 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 오블완
- uiux
- 서비스기획
- 구글머터리얼디자인
- css
- 웹접근성
- 웹디자인
- 바이브코딩
- UX디자인
- 머터리얼디자인
- ai사주
- 2024웹디자인
- CSS3
- figma
- JavaScript
- html
- 웹폰트
- 웹퍼블리싱
- 디자인팁
- 디자인시스템
- 티스토리챌린지
- 웹디자인개발기능사
- 피그마
- 웹디자인팁
- 찐망고사주
- 웹표준
- 프론트엔드
- 반응형웹
- UI디자인
- seo
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함