inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

BBC 인터랙티브 페이지 "코로나19가 바꿀 사무실의 미래" 클론

오류났을때 참고

685

amilyy70096

작성한 질문수 2

3

안녕하세요 , 23년도에도 듣고 계신 분이 계실지는 모르겠지만.. 강의 들으면서 혹시 막히시는 부분들 제가 수업 들으면서 작성한 코드와 비교해서 본인이 작성한 어떤 부분이 잘못되었는지 확인하시면 문제해결에 도움이 될듯해서요 !

위 두가지에서 시간이 좀 잡아먹었는데 저와같은 분들이라면 제 js 랑 비교해보세요 ㅋㅋ

( 이 부분은 애니메이션이 완전히 끝까지 완료 후 스크롤을 내려야 다시 활성화 되었을 때 애니메이션이 제자리에서 작동을 하더라구요. )


html {
	font-family: 'Noto Sans KR', sans-serif;
}
body {
	margin: 0;
}
div, section, header, footer, p, h1, h2 {
	box-sizing: border-box;
}
a {
	color: royalblue;
}
img {
	max-width: 100%;
	height: auto;
	
}

/* 배경이 되는 이미지들 */
.global-width{
	max-width: 620px;
	margin: 0 auto;
	padding: 0 1rem;
	
}

.scroll-graphic{
	overflow-x: hidden;
	position:sticky;
	top:0;
	height: 100vh;

}
.graphic-item{
	display: flex;
	align-items: center;
	justify-content: center;
	position:absolute;
	left: 0;
	top:0;
	width: 100vw;
	height: 100vh;
	opacity: 0;
	transition: 0.5s;
	will-change: opacity;
}
.visible{
	opacity: 1;
}

.scene-img{
	max-height: 100vh;
}

.scroll-text{
	position: relative;
	padding-bottom: 1px;
}

.step{
	margin-bottom: 60vh;
	padding: 0.5rem 1rem;
	border-radius: 10px;
	border : 0.2px solid rgba(216,216,216,0.2);
	box-shadow: rgba(0,0,0,0.3)0 0 3px;
	background: rgba(255,255,255,0.8);
}
.bird{
	position:absolute;
	left: 0;
	bottom:70%;
	width: 100px;
	transform:translateX(-100%);
	transition:1.5s 0.5s linear;
}

[data-index="5"] .bird{
	left: 30%;
	bottom:30%;
}

.global-footer{
	text-align: center;
	padding:2rem 0;
}
.strikethrough{
	text-decoration: line-through;
}
// 전역변수 사용 회피 
(() => {

    const actions = {
        birdFlies(key){
        if (key) {
            document.querySelector('[data-index="2"] .bird').style.transform = `translateX(${window.innerWidth}px)`;
        }else{
            document.querySelector('[data-index="2"] .bird').style.transform = `translateX(-100%)`;
        }
      },

      birdFlies2(key) {

        if (key) {
            document.querySelector('[data-index="5"] .bird').style.transform = `translate(${window.innerWidth}px, ${-window.innerHeight * 0.7}px)`;
        }else{
            document.querySelector('[data-index="5"] .bird').style.transform = `translateX(-100%)`;
        }
    }

};


    const stepElems = document.querySelectorAll('.step');
    const graphicElems = document.querySelectorAll('.graphic-item');
    let currentItem = graphicElems[0]; 
    let ioIndex;

    const io = new IntersectionObserver((entries,observer)=>{
     
        ioIndex = entries[0].target.dataset.index *1 ;
        console.log(ioIndex);
    })
    for (let i = 0; i < stepElems.length; i++) {
 
        io.observe(stepElems[i]);
        stepElems[i].dataset.index = i;
        graphicElems[i].dataset.index = i;
    }



    function activate(action) {
        currentItem.classList.add('visible');
        if (action) {
            actions[action](true);
        }
    }

    function inactivate(action) {
        currentItem.classList.remove('visible');
        if (action) {
            actions[action](false);
        }
    }
 

    window.addEventListener('scroll', () => {

        let step;
        let boundingRect;
       
        for (let i=ioIndex-1; i<ioIndex+2; i++){
           
            step = stepElems[i];
            if(!step) continue;

            boundingRect = step.getBoundingClientRect();
           
            if(boundingRect.top > window.innerHeight*  0.1 &&
                boundingRect.top < window.innerHeight*0.8){
                 
                    inactivate(currentItem.dataset.action);
                    currentItem = graphicElems[step.dataset.index];
                    activate(currentItem.dataset.action);
                    
                   
            }

           
        }
    });

    window.addEventListener('load',()=>{
        setTimeout (() => scrollTo(0,0),100);
    })
    activate();
})();

 

인터랙티브-웹 클론코딩 클론코딩 인터랙티브-웹

답변 3

0

Min Ji Park

감사합니다~! 덕분에 해결했습니다~!

0

eunseon

감사합니다. 비활성화된게 다시 활성화 안되서 어떻하나 했는데 밑에 inactivate()안에 안넣어서 그랬네요 ㅎㅎ.

 

0

피로한 펭귄

감사합니다 ㅎㅎ 비활성화된게 안돌아와서 한참 찾았는데 해결했네요 ^^

imagesLoaded에 관한 질문

0

0

0

더백님 감사합니다

1

33

1

ai 도구 질문

0

30

1

video_call 플러그인 설치후 에러 발생

0

41

1

MCP 연동 인텔리제이 2.6.1

0

113

2

MCP 연동관련

0

129

4

클로드 개발자 구성편집 설정시 문제점

0

94

2

2025.3.3 인텔리제이 버전에서 MCP설정하는 방법

0

312

2

box3.position.x 위치

0

36

1

SDK 안드로이드 설치 질문!

0

56

1

React에도 적용 가능한가요?

0

299

1

style.css 오류

0

307

1

actions 함수 관련 질문

2

400

1

새가 원래자리로 돌아올때도 transition 시간이 필요한데. 돌아올때는 바로 돌아오록 하는 Tip 이 있을까요?

0

249

0

classList 오류가 계속 납니다..ㅜㅜ

0

395

0

새 애니메이션이 작동하지 않습니다.

0

239

1

action이 true일때 실행되는데 false에서 초기화가 안되요ㅠ

0

335

2

오류가 나는데 찾지를 못하겠어요...

0

376

2

안녕하세요 ~~ 배경으로 깔린 음악이 너무 궁금하네요 ㅎㅎ

0

540

2

actions[action] is not a function 라고 뜹니다

0

994

5

첫번째랑 마지막 요가+폰하는 그림이 높이가 꼬였습니다

0

466

4

forEach로 작성해봤습니다!

1

285

1

안녕하세요, step부분 문의 드립니다.

0

218

1

질문있습니다!

2

310

2