inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

인터랙티브 개발 실무 끝장내기 [역량 강화편]

이벤트 돌림판 - 랜덤, rotate 속성, transition

질문 있습니다

해결된 질문

255

당황한 노새

작성한 질문수 12

2

위와같이 하고 있는데요.

화살표가 0에 위치했다가 다시 돌아가게끔 해주고싶은데,

처음에 400도가 나왔다고 하면 해당 위치에서 다음 값의 위치로만 움직입니다. 해당 이슈를 해결하려면 어떻게 해야할까요..?

아래 코드 첨부했습니다!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
div {
width: 400px;
height: 400px;
background: red;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
h1 {
font-size: 80px;
transition: all 600ms cubic-bezier(1, -0.06, 0.985, 1.01);
}
</style>
</head>

<body>
<div>
<h1></h1>
</div>
<button>동작</button>
<script>
const btn = document.querySelector("button");
const arrow = document.querySelector("h1");

const arrowRotate = (aLot = 5) => {
const rotateValue = aLot * 360 + Math.ceil(Math.random() * 360);
arrow.style.transform = `rotate(${rotateValue}deg)`;
};
const arrowInit = () => {
arrow.style.transition = "0";
arrow.style.transform = `rotate(0deg)`;
};
const moveArrow = (aLot) => {
arrowInit();
setTimeout(() => {
arrowRotate(aLot);
}, 1000);
};

btn.addEventListener("click", () => {
moveArrow();
});
</script>
</body>
</html>

 

javascript 인터랙티브-웹

답변 1

1

코딩일레븐

안녕하세요.

const arrowInit = () => {

 arrow.style.transitionDuration  = "0s";   <- 이부분을 수정하시면 됩니다.

 arrow.style.transform = `rotate(0deg)`;

};

const arrowRotate = (aLot = 5) => {

const rotateValue = aLot * 360 + Math.ceil(Math.random() * 360);

arrow.style.transitionDuration  = "1s";

arrow.style.transform = `rotate(${rotateValue}deg)`;

};

css의 transition-duration time을 바꿔주는 겁니다.

transition: all 1s cubic-bezier(1, -0.06, 0.985, 1.01);

모바일 스와이프 구현 마지막 숙제

0

402

2

레퍼런스 사이트

0

339

1

스크롤위치에 따른 페이지 변화에서

0

267

1

배열을 이용한 bg컬러 변경 강의에서 tagname body에 [0]이 왜 붙나요?

0

380

1

스크롤 위치에 따른 페이지 변화 - scroll 이벤트 에 대한 질문

0

675

1

페이징.페이지고정2 질문드립니다.

0

459

1

scrollTo 완성본

0

603

2

모바일 3D 입체 카드 제작 아이폰에서 에러

0

386

1

css 질문 드립니다

0

623

1

css 질문

0

284

1

pointBtn.addEventListner("click")

0

305

2

if문의 첫번째 조건 질문 있습니다~

0

285

1

offsetTop, offsetHeight

0

785

2

기존의 축 회전값에 더해서 rotate

0

320

1

모바일 드래그 강의 질문드립니다!

0

256

1

질문입니다.

0

215

1

GSAP(트윈맥스) 라이센스 관련 질문 드립니다.

0

1657

1

wrap 안에 click 이벤트

0

225

1

greensock을 사용하려면

0

701

1

TweenMax 효과 리셋

0

524

1

max 이상으로 입력했을 때 질문입니다.

0

192

1

dom에서 직접i nput의 value 값을 갖고 나오는 것에 대해

0

370

1

화살표 회전 질문

0

261

1

질문이용~

0

218

1