강의

멘토링

커뮤니티

Inflearn Community Q&A

zzzwwwrrr667444's profile image
zzzwwwrrr667444

asked

Getting Started with Interactive Web Development

3 doors 5

잘보고 있습니다. 질문있습니다!

Written on

·

153

0

stage를 클릭했을때 문이 닫히지 않는건 성공했는데 

문이 열려있는 자기 자신을 클릭했을때 remove가 되는방법 알고싶어요..!

HTML/CSS인터랙티브-웹javascript

Answer 1

1

studiomeal님의 프로필 이미지
studiomeal
Instructor

doorHandler 함수를 아래와 같이 바꿔 보세요 :)

추가된 부분에 주석으로 설명을 달아 두었습니다.

 

function doorHandler(e) {

  const targetElem = e.target;

 

  if (currentItem) {

    inactivate(currentItem);

  }

 

  if (targetElem.classList.contains('door-body')) {

    // currentItem targetElem.parentNode를 비교해서

    // 같은 객체이면 열지 않고 return으로 함수 종료

    if (currentItem == targetElem.parentNode) {

      currentItem = null;

      return;

    }

    activate(targetElem.parentNode);

  }

}

zzzwwwrrr667444's profile image
zzzwwwrrr667444

asked

Ask a question