-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ 2주차 기본/심화 ] 웨비의 사진관 😋 #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 바로 우수과제mvp..✨
@@ -0,0 +1,103 @@ | |||
const $ = (selector) => document.querySelector(selector); | |||
const $$ = (selector) => document.querySelectorAll(selector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 방법이... 가독성도 더 좋아지고 우리도 쓰기 편해서 넘 좋다!!
const handleTopBtnOpacity = () => { | ||
const topBtn = $(".to-top"); | ||
//top 버튼과 뷰포트의 상대적인 위치 정보를 받아옴 | ||
const topBtnHeight = topBtn.getBoundingClientRect().height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getBoundingClientRect()메서드를 처음 알았어! 이번 과제 하면서 요소의 속성이랑 메서드가 진짜 다양하다는걸 깨닫는당..
언니가 prpoint에 올려준 링크 참고해서 리뷰 반영할 때 적절한 메서드 사용해봐야겠어!!
|
||
//***** 설명 더보기 버튼 구현 ***** | ||
// 더보기 버튼 보여주는 핸들러 함수 | ||
const handleshowMoreBtn = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수 기능별로 나누는거 넘 좋은거같아!
이 함수에선 설명부분 foreach로 돌면서 길이 검사해서 더보기를 넣어주는거라고 이해했는데 이 방법은 어떤지 함 봐주라!
유진언니 코드에서 보니까 html에 제목이랑 설명을 태그로 넣어두지 않고 img에 속성으로 추가해놓고 js로 태그 만들어서 추가해주는 방법을 했더라구 이런 방법에선
검사하는 기능만 있는 함수를 만들고 설명태그 만들어주는 함수에서 검사하는 함수 불러다가 검사하는 방법으로 하면 함수 내부애 foreach가 없어서 함수가 더 최소한의 기능을 할 수 있을거같다는 생각이 들었어ㅎㅎㅎ!!
const moreBtn = document.createElement("button"); | ||
moreBtn.setAttribute("type", "button"); | ||
moreBtn.classList.add("detail__more-btn"); | ||
moreBtn.innerHTML = "더보기"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
태그안에 텍스트나 html넣어줄 때 innerHTML이랑 innerText, textContent중에 뭘 써야할지 궁금해서 찾아보다가
https://velog.io/@kim_unknown_/JavaScript-Difftext
잘 정리해둔 글이 있어서 공유하고 갑니다롱
const previewSection = $(".preview-section"); | ||
|
||
leftArrowBtn.addEventListener("click", () => { | ||
previewSection.scrollLeft = previewSection.offsetLeft; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scrollLeft나 offsetLeft 이런 속성들도 되게 생소하다.. 과제할 때 기능을 위한 적절한 속성이 있는지 찾아보는 연습을 해봐야겠오
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고많았어!!! 코드 넘 이뻐 다 흡수해가야징 히히
|
||
// 설명 보이기 -> show-describe 클래스 붙여주기 | ||
const showDescription = (event) => { | ||
event.target.classList.add("show-describe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와 나는 hover 될때마다 설명 요소에 직접 접근해서 요소.style.visibility="visible" 이런식으로 직접 제어하도록 했는데 연서가 한 방법이 속도 측면에서도 훨씬 좋을듯!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그리고 결정적으로 코드도 깔끔해 ,,
event.target.classList.remove("show-describe"); | ||
|
||
// 더보기 상태 초기화 | ||
const detailContents = $$(".description__detail"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
초기화도 따로 함수로 빼니까 가독성이나 유지보수할때 훨씬 더 좋을거같다!!
const details = $$(".description__detail"); | ||
details.forEach((detail) => { | ||
if (detail.innerHTML.length > 70) { | ||
const moreBtn = document.createElement("button"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
나는 이거 button 대신 input type="button"으로 했어!! css 파일에서 input checked일때에 대해서 쉽게 조작하려고 한건데, 생각처럼 쉽게 안되길래 나도 그냥 onClick 이벤트 설정해줬어 키키
); | ||
}; | ||
|
||
//***** 최종 실행 함수(핸들러 함수) ***** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와 먼가 파이썬같아 깔끔해..!!
코드가 기능따라서 다 함수로 분리되어있으니까 보기 정말 편하다!!
✨ 구현 기능 명세
⭐️기본 과제
1. 이미지 (첫번째 섹션만 해당)
이미지 호버시 백그라운드가 어둡게 처리되고, 해당 사진에 대한 제목과 설명이 나타납니다.
이미지에서 벗어나면 사라집니다.
→ 한번에 반드시 하나의 이미지의 설명만 나타납니다.
2. top버튼
⭐️ 심화 과제
1. 이미지
3줄 이상인 설명은 말줄임표 처리와, 더보기 버튼이 나타납니다.
더보기 클릭시 설명이 모두 보입니다.
→ 설명은 넘치지 않도록 넣어주세요!
2. preview section
💎 PR Point
1️⃣ 이미지 hover 시 설명 나타나도록 (기본) + 3줄 이상 말줄임표 , 더보기 버튼 (심화)
2️⃣ top Btn (기본)
3️⃣ 좌우 스크롤 좌/우 이동 버튼 (심화)
4️⃣ 기타 신경 쓴 부분
🥺 소요 시간, 어려웠던 점
3h
🌈 구현 결과물
배포 링크