2020-NAVER-CAMPUS-HACKDAY / Influencer

🧏🏻 간단한 사용자 인터랙션을 통한 상품 추천 및 전시 개발 (a.k.a 쇼핑의 신) 🚚
109 stars 7 forks source link

클릭했을때 센터링 애니메이션 #146

Open jominjimail opened 4 years ago

jominjimail commented 4 years ago

따란🤧😫🔫

Jun-05-2020 04-15-49

목표 움직임 transform: translate(-20px, 0px)

KakaoTalk_Photo_2020-06-05-13-21-40

잠깐 짚고넘어가야 할 용어들

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;

KakaoTalk_Photo_2020-06-05-13-24-27

~여러분 안 읽을거 알지만 🤧~ 간단한 예시 설명

KakaoTalk_Photo_2020-06-05-13-30-20 KakaoTalk_Photo_2020-06-05-13-32-47

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}

// 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) {
    // --->
    ...

하지만, 문제가 있습니다. 😇🔫

KakaoTalk_Photo_2020-06-05-13-54-30

Jun-05-2020 04-18-16

jominjimail commented 4 years ago

참고: m.naver.com의 nav-scroll을 참고하면서 코드를 짰습니다. image

minsour commented 4 years ago

크 고생하셨습니다 :) 마지막에 문제가 있다는 부분이 이해가 안되는데, 스크롤 기능이 있어서 확인 가능하다는 게 어떤거에요??