inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

JS part 2

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

375

kain74

작성한 질문수 4

0

// 즉시실행 인명함수
(() => {

    const actions = {
        bordFlies(){
            document.querySelector(['data-index="2"'.bird).style.transform = `translateX($(window.innerWidth)px)`;
        }
    }

    const stepElems = document.querySelectorAll('.step');
    const graphicElems = document.querySelectorAll('.graphic-item');
     // 현재 활성화된(visible 클래스가 붙은) .graphic-item을 지정
    let currentItem = graphicElems[0];
    let ioIndex;

    const io = new IntersectionObserver((entries, observer) => {
        //console.log(entries[0].target.dataset.index);
        ioIndex = entries[0].target.dataset.index * 1;
        //console.log(iosIndex);
    });

    for(let i=0; i< stepElems.length; i++){
        io.observe(stepElems[i]);
        //stepElems[i].setAttribute('data-index', i);
        stepElems[i].dataset.index = i;
        graphicElems[i].dataset.index = i;
        //console.log(stepElems[i].setAttribute('data-index', i));
    }

    // 활성화
    function activate(action){
        currentItem.classList.add('visible');
        if(action){
            actions[action](); // 오류
        }
        console.log(action);
    }

    // 비활성화
    function inactivate(){
        currentItem.classList.remove('visible');
    }

    window.addEventListener('scroll', () => {
        let step;
        let boundingRect;
        let temp = 0;
        //for (let i = 0; i < stepElems.length; i++){
        for (let i = ioIndex - 1; i < ioIndex + 2; i++){
            step = stepElems[i];
            if(!stepcontinue;
            boundingRect = step.getBoundingClientRect();
            //console.log(boundingRect.top);
            temp++;
            // 범위설정
            if(boundingRect.top > window.innerHeight * 0.1  && boundingRect.top < window.innerHeight * 0.8){
                //console.log(step.dataset.index);
                //graphicElems[step.dataset.index].classList.add('visible');
                if(currentItem){
                    inactivate();
                }
                currentItem = graphicElems[step.dataset.index];
                activate(currentItem.dataset.action);  // 오류
            }
        }

        console.log(temp);
    });

    activate();
})();// 즉시실행 인명함수
(() => {

    const actions = {
        bordFlies(){
            document.querySelector(['data-index="2"'.bird).style.transform = `translateX($(window.innerWidth)px)`;
        }
    }

    const stepElems = document.querySelectorAll('.step');
    const graphicElems = document.querySelectorAll('.graphic-item');
     // 현재 활성화된(visible 클래스가 붙은) .graphic-item을 지정
    let currentItem = graphicElems[0];
    let ioIndex;

    const io = new IntersectionObserver((entries, observer) => {
        //console.log(entries[0].target.dataset.index);
        ioIndex = entries[0].target.dataset.index * 1;
        //console.log(iosIndex);
    });

    for(let i=0; i< stepElems.length; i++){
        io.observe(stepElems[i]);
        //stepElems[i].setAttribute('data-index', i);
        stepElems[i].dataset.index = i;
        graphicElems[i].dataset.index = i;
        //console.log(stepElems[i].setAttribute('data-index', i));
    }

    // 활성화
    function activate(action){
        currentItem.classList.add('visible');
        if(action){
            actions[action](); // 오류
        }
        console.log(action);
    }

    // 비활성화
    function inactivate(){
        currentItem.classList.remove('visible');
    }

    window.addEventListener('scroll', () => {
        let step;
        let boundingRect;
        let temp = 0;
        //for (let i = 0; i < stepElems.length; i++){
        for (let i = ioIndex - 1; i < ioIndex + 2; i++){
            step = stepElems[i];
            if(!stepcontinue;
            boundingRect = step.getBoundingClientRect();
            //console.log(boundingRect.top);
            temp++;
            // 범위설정
            if(boundingRect.top > window.innerHeight * 0.1  && boundingRect.top < window.innerHeight * 0.8){
                //console.log(step.dataset.index);
                //graphicElems[step.dataset.index].classList.add('visible');
                if(currentItem){
                    inactivate();
                }
                currentItem = graphicElems[step.dataset.index];
                activate(currentItem.dataset.action);  // 오류
            }
        }

        console.log(temp);
    });

    activate();
})();// 즉시실행 인명함수
(() => {

    const actions = {
        bordFlies(){
            document.querySelector(['data-index="2"'.bird).style.transform = `translateX($(window.innerWidth)px)`;
        }
    }

    const stepElems = document.querySelectorAll('.step');
    const graphicElems = document.querySelectorAll('.graphic-item');
     // 현재 활성화된(visible 클래스가 붙은) .graphic-item을 지정
    let currentItem = graphicElems[0];
    let ioIndex;

    const io = new IntersectionObserver((entries, observer) => {
        //console.log(entries[0].target.dataset.index);
        ioIndex = entries[0].target.dataset.index * 1;
        //console.log(iosIndex);
    });

    for(let i=0; i< stepElems.length; i++){
        io.observe(stepElems[i]);
        //stepElems[i].setAttribute('data-index', i);
        stepElems[i].dataset.index = i;
        graphicElems[i].dataset.index = i;
        //console.log(stepElems[i].setAttribute('data-index', i));
    }

    // 활성화
    function activate(action){
        currentItem.classList.add('visible');
        if(action){
            actions[action](); // 오류
        }
        console.log(action);
    }

    // 비활성화
    function inactivate(){
        currentItem.classList.remove('visible');
    }

    window.addEventListener('scroll', () => {
        let step;
        let boundingRect;
        let temp = 0;
        //for (let i = 0; i < stepElems.length; i++){
        for (let i = ioIndex - 1; i < ioIndex + 2; i++){
            step = stepElems[i];
            if(!stepcontinue;
            boundingRect = step.getBoundingClientRect();
            //console.log(boundingRect.top);
            temp++;
            // 범위설정
            if(boundingRect.top > window.innerHeight * 0.1  && boundingRect.top < window.innerHeight * 0.8){
                //console.log(step.dataset.index);
                //graphicElems[step.dataset.index].classList.add('visible');
                if(currentItem){
                    inactivate();
                }
                currentItem = graphicElems[step.dataset.index];
                activate(currentItem.dataset.action);  // 오류
            }
        }

        console.log(temp);
    });

    activate();
})();

인터랙티브-웹 클론코딩

답변 2

0

kain74

아 그런가요?  처음부터 똑같이 따라했는데... 다시 봐야겠네요 ㅠㅠ

0

kde

에러 메시지 화면, 그 에러랑 관련있는 코드를 캡쳐해 주셔야 도와드릴 수 있어요.

즉시실행 익명함수 3개?? 정도 주셨는데 세 개 어떻게 다른 건지 안알려주셔서 맨 처음 꺼만 봤어요. 

일단 위에 캡쳐만 보면 저희 수업할 때 코드랑 많이 다른 거 같아요 아직 코드 덜 작성하신 것 같아요.

actions 메소드 두 개 필요한데 일단 님은 하나밖에 안 만드신 것 같아요. 

html에 data-action을birdFlies랑 birdFlies2 두 개 추가했었기 떄문에 메소드도 두개 필요하거든요. 근데

birdFlies 꺼만 만드셨어요. 스크롤 되면서 birdFlies2 호출할 때 해당 함수가 없어서

에러났을 것 같아요.

LocationPermission.denied관련 질문입니다

0

585

1

writeHead 부분

0

466

1

로그인페이지, 회원가입페이지 못들어가게하는 부분

0

516

1

강의에서 사용하고 있는 next.js 버전으로 설치는 어떻게 하나요?

0

2342

1

[공유] react-mention 항상 커서 위에 나오게 수정

2

882

3

videocontrollor dispose

0

427

1

user 과 auth에서 인증 부분

0

447

1

onlogotap함수의 video nullable관련질문

0

387

1

채팅대화에서 시간이 중복될경우 안보이게 하는방법 문의.

0

542

1

쿠키에 대해서

0

315

1

next.js 버전이 12인건가요?

0

367

1

오류났을때 참고

3

685

3

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

334

2

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

0

540

2

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

0

993

5

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

0

465

4

forEach로 작성해봤습니다!

1

285

1

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

0

218

1

질문있습니다!

2

310

2