Open jominjimail opened 4 years ago
const clientWidthCenter = document.body.clientWidth / 2; const scrollWidth = document.getElementById('section_scroll').getBoundingClientRect().width; const firstCardElement = document.getElementById('firstCard'); const firstCardX = firstCardElement.getBoundingClientRect().x; const { x, width } = event.currentTarget.getBoundingClientRect(); // targetCard const targetCenter = x + width / 2; const scrollBegin2targetCenter = Math.abs(firstCardX) + targetCenter; const targetCenter2scrollEnd = scrollWidth - scrollBegin2targetCenter; const clientCenter2targetCenter = clientWidthCenter - targetCenter;
// Case1 : 움직이지 않는다. (default) let canMove = false; let translate = 0; if (client2target < 0) { // <--- if (target2End - Math.abs(client2target) > 0) { // Case3: 쉽게 움직인다. canMove = true; translate = client2target; if (target2End < clientHalfWidth) { // Case2: 보강하면서 움직인다. translate = client2target + (clientHalfWidth - target2End); } } } else if (client2target >= 0) { // ---> ...
참고: m.naver.com의 nav-scroll을 참고하면서 코드를 짰습니다.
크 고생하셨습니다 :) 마지막에 문제가 있다는 부분이 이해가 안되는데, 스크롤 기능이 있어서 확인 가능하다는 게 어떤거에요??
따란🤧😫🔫
목표 움직임 transform: translate(-20px, 0px)
잠깐 짚고넘어가야 할 용어들
~여러분 안 읽을거 알지만 🤧~ 간단한 예시 설명
1번 카드: Case1 : 움직이지 않는다. {canMove: false, translate: 0}
2번 카드: Case2 : 보강하면서 움직인다. {canMove: true, translate: 0}
3번 카드: Case3 : 쉽게 움직인다. {canMove: true, translate: -5}
4번 카드: Case3 : 쉽게 움직인다. {canMove: true, translate: -5}
5번 카드: Case2 : 보강하면서 움직인다. {canMove: true, translate: 0}
6번 카드: Case1 : 움직이지 않는다. {canMove: false, translate: 0}
하지만, 문제가 있습니다. 😇🔫