-
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주차 기본/심화 과제] 웨비의 사진관 😋 #4
Changes from 1 commit
e425894
8bf3228
7348a96
c592135
c34a82d
adc3f9d
f5a0490
b33f1b5
7872707
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -7,14 +7,21 @@ document.addEventListener("scroll", () => { | |||||||
topBtn.style.opacity = window.scrollY / windowHeight / 2; | ||||||||
}); | ||||||||
|
||||||||
/* 글자수에 따른 더보기 버튼 활성화 및 작동 */ | ||||||||
const moreBtn = document.createElement("button"); //button 요소 생성 | ||||||||
moreBtn.innerText = "more"; | ||||||||
moreBtn.setAttribute("class", "content-more-btn"); //button 클래스명 지정 | ||||||||
|
||||||||
const contents = document.querySelectorAll(".content"); | ||||||||
contents.forEach((content) => { | ||||||||
if (content.children[1].innerText.length >= 85) { | ||||||||
content.appendChild(moreBtn); | ||||||||
const contentDescription = content.children[1]; | ||||||||
/* 글자수에 따른 더보기 버튼 활성화 및 작동 */ | ||||||||
if (contentDescription.innerText.length >= 85) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR에 적어준 부분인 것 같아서,
Suggested change
저는 이런식으로 사용해서 구현했어용 참고 !~! |
||||||||
const moreBtn = document.createElement("button"); //button 요소 생성 | ||||||||
moreBtn.innerText = "more"; | ||||||||
moreBtn.setAttribute("class", "content-more-btn"); //button 클래스명 지정 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setAttribute 외에도 classList.add 를 이용하는 방식도 있어요!! 이를 이용하는 것이 속도면에서 더 빠르다는 얘기가 있네요~ 한 번 참고해 보시는 것도 좋을 거 같아요!! 참고자료 https://measurethat.net/Benchmarks/Show/54/0/classname-vs-setattribute-vs-classlist |
||||||||
|
||||||||
content.appendChild(moreBtn); //button 붙이기 | ||||||||
|
||||||||
/* 클릭 이벤트시 버튼 사라짐 */ | ||||||||
content.addEventListener("click", () => { | ||||||||
contentDescription.style.display = "block"; //말줄임 표시를 없앰 | ||||||||
moreBtn.style.display = "none"; | ||||||||
}); | ||||||||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addEventListener가 content에 있는데 버튼 클릭 시가 아니라 내용 클릭시 내용이 다 보이게 구현하신건가용..? |
||||||||
} | ||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,8 @@ section > h1 { | |
|
||
padding: 0.5rem 1rem; | ||
border-radius: 1rem; | ||
|
||
cursor: pointer; | ||
} | ||
|
||
/* second section */ | ||
|
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.
저는 y축 스크롤 된거를 스크롤할 수 있는 최대치로 나눠서 구현했는데 이렇게도 할 수 있군요!