我做了下列菜單圖標的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").click(
function(){
$("#path1, #halfLineLeft, #halfLineRight").css("animation-play-state", "running");
}
);
我似乎無法弄清楚如何使它在反向動畫時,我對SVG圖標點擊第二次。我想這個代碼沒有任何的運氣:
$("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