前提・実現したいこと
スマートフォンで表示するサイトに動きを加えたいと思っています。
クリックした画像が上に移動してそこで違う画像に変化するというものです。
Animate.css(https://daneden.github.io/animate.css/)で試していますが
画像が上にすーっと移動して、その場所で別の画像に切り替わるのではなく
元の画像の場所で切り替わってしまいます。
「animation-fill-mode: forwards」を指定しましたが利かないようです。
下記のcssにプラスしてanimate.cssとjqueryを読みこんでいます。
全文は重くて貼れないので修正箇所のみ記載しています。
該当のソースコード
HTML
1<img class="ani-logo" src="https://placehold.jp/150x150.png" alt="" />
javaScript
1$(function(){ 2 $(".ani-logo").on({ 3 "click":function(){ 4 $(this).addClass("animated zoomOutUp"); 5 }, 6 "webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend":function(){ 7 $(this).removeClass("animated zoomOutUp"); 8 $(this).attr("src", "http://placehold.jp/24/cc9999/993333/150x100.png"); 9 } 10 }); 11});
css
1/* (animate.cssから、修正を入れた場所のみ抜粋) */ 2 3@-webkit-keyframes zoomOutUp { 4 40% { 5 opacity: 1; 6 -webkit-transform: scale3d(0.475, 0.475, 0.475) translate3d(0, 60px, 0); 7 transform: scale3d(0.475, 0.475, 0.475) translate3d(0, 60px, 0); 8 -webkit-animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); 9 animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); 10 } 11 12 to { 13 opacity: 0; 14 -webkit-transform: scale3d(0.1, 0.1, 0.1) translate3d(0, -2000px, 0); 15 transform: scale3d(0.1, 0.1, 0.1) translate3d(0, -2000px, 0); 16 -webkit-transform-origin: center bottom; 17 transform-origin: center bottom; 18 -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1); 19 animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1); 20 } 21} 22 23@keyframes zoomOutUp { 24 40% { 25 opacity: 1; 26 -webkit-transform: scale3d(0.475, 0.475, 0.475) translate3d(0, 60px, 0); 27 transform: scale3d(0.475, 0.475, 0.475) translate3d(0, 60px, 0); 28 -webkit-animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); 29 animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19); 30 } 31 32 to { 33 opacity: 0; 34 -webkit-transform: scale3d(0.1, 0.1, 0.1) translate3d(0, -2000px, 0); 35 transform: scale3d(0.1, 0.1, 0.1) translate3d(0, -2000px, 0); 36 -webkit-transform-origin: center bottom; 37 transform-origin: center bottom; 38 -webkit-animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1); 39 animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1); 40 } 41} 42 43.zoomOutUp { 44 -webkit-animation-name: zoomOutUp; 45 animation-name: zoomOutUp; 46 -webkit-animation-fill-mode: forwards !important; 47 animation-fill-mode: forwards !important; 48} 49 50.animated { 51 -webkit-animation-duration: 1s; 52 animation-duration: 1s; 53 -webkit-animation-fill-mode: forwards !important; 54 animation-fill-mode: forwards !important; 55} 56
試したこと
教えていただいて、元の画像を別の画像に切り替えるところまではできました。
animate.cssにanimation-fill-modeを設定しました。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。