다음 메뉴 아이콘 CSS 애니메이션을 클릭했을 때 트리거합니다. jQuery를 사용하여 두 번째로 클릭 할 때 역 애니메이션으로 만들고 싶습니다.jQuery로 두 번째 클릭시 CSS 애니메이션을 뒤집는 방법
#path1 {
stroke-dasharray: 33px;
stroke-dashoffset: 33px;
animation: line 1.5s linear forwards;
animation-play-state: paused;
}
@keyframes line {
100% {
stroke-dashoffset: -15.5;
}
}
#halfLineLeft {
transform-origin: 1% 50%;
animation: shrinkleft 1s linear forwards;
animation-play-state: paused;
}
#halfLineRight {
transform-origin: 100% 1%;
animation: shrinkleft 1s linear forwards;
animation-play-state: paused;
}
@keyframes shrinkleft {
100% {
transform: scale(0,1);
}
}
svg {
transform: translate(350px, 200px);
}
이 내가 지금까지 가지고있는 jQuery를이다 ... 나는 내가 SVG 아이콘을 두 번째로 클릭하면 그 역으로 애니메이션을 만드는 방법을 알아낼 질수
$("svg").click(
function(){
$("#path1, #halfLineLeft, #halfLineRight").css("animation-play-state", "running");
}
);
. 나는 운이없이이 코드를 시도 :
여기$("svg").click(
function(){
$("#path1, #halfLineLeft, #halfLineRight").css("animation-state", "running"),
$("#path1, #halfLineLeft, #halfLineRight").css("animation-direction", "reverse");
}
);
라이브 애니메이션과 codepen 링크입니다 :
http://codepen.io/anon/pen/xEORBJ
은 아마 당신은 클릭 수를 저장하는 변수를 추가 할 수 있습니다. 첫 번째 클릭은 첫 번째 애니메이션을 실행하고, 두 번째 클릭은 다른 애니메이션을 실행합니다. – Trialsman
@Trialsman 또는 true에서 false로 바뀌거나 뒤로 돌아 오는 부울. 그리고 클릭 할 때마다 'whichAnimation =! whichAnimation' –
당신은 이것을 위해 수업을 토글하는 것을 고려 했습니까? – charlietfl