Rubu on Railsでいいね機能を作ったのですがボタンを押したときにアニメーションをつけたいのですが、いろいろ調べてもよくわかりませんでした。
https://nelog.jp/twitters-fave-animation や https://yuyauver98.me/twitter-like-animation/ を見たのですがいいねにアニメーションを実装することはできませんでした(hoverでアニメーションを動作させることはできた)
詳しい方教えていただけると幸いです。
###index.html
HTML
1<span id="likes_buttons_<%= post.id.to_s %>"> 2 <%= render partial: 'likes/like', locals: { post: post} %> 3</span>
CSS
CSS
1.love { 2 background-image: image-url("likeoff"); 3 background-repeat: no-repeat; 4 height: 18px; 5 width: 18px; 6 background-size: 18px !important; 7 float: left; 8 margin-top: 3px; 9 transition: all .15s ease; 10 animation: populate .5s ease-out normal backwards; 11 } 12 13 .love:hover { 14 transform: scale(1.05); 15 } 16 .loved { 17 background-image: image-url("likeon"); 18 background-repeat: no-repeat; 19 height: 18px; 20 width: 18px; 21 background-size: 18px !important; 22 float: left; 23 margin-top: 3px; 24 }
###_like.html.erb
<div class="like-area" id="like-icon-post-<%= post.id.to_s %>"> <% if post.liked_by(current_user).present? %> <%= link_to "いいねを取り消す", post_like_path(post.id, post.liked_by(current_user)), method: :DELETE, remote: true, class: "loved hide-text" %> <span class="like-count"><%= post.likes.count %></span> <% else %> <%= link_to "いいね", post_likes_path(post), method: :POST, remote: true, class: "love hide-text" %> <span class="like-count"><%= post.likes.count %></span> <% end %> </div>
create.js.erb
$('#like-icon-post-<%= @post.id.to_s %>'). html('<%= link_to "いいね", post_like_path(@post.id, @like), method: :DELETE, remote: true, class: "loved hide-text" %>'); $('#likes_buttons_<%= @post.id.to_s %>').html("<%= j(render partial: 'likes/like', locals: {post: @post}) %>");
###destroy.js.erb
$('#like-icon-post-<%= @post.id.to_s %>'). html('<%= link_to "いいねを取り消す", post_likes_path(@post), method: :POST, remote: true, class: "love hide-text" %>'); $('#likes_buttons_<%= @post.id.to_s %>').html("<%= j(render partial: 'likes/like', locals: {post: @post}) %>");