Please take a look at the code snippet below.
$(document).ready(function(){
$(".like-btn").hover(function() {
var rowid = $(this).attr("data-rowid");
$(".reaction-box[data-rowid='" + rowid + "']").fadeIn(100, function() {
$(".reaction-icon").each(function(i, e) {
setTimeout(function(){
$(e).addClass("shows");
}, i * 100);
});
});
}, function() {
var rowid = $(".like-btn").attr("data-rowid");
setTimeout(function(){
$(".reaction-box[data-rowid='" + rowid + "']").fadeOut(300, function(){
$(".reaction-icon").removeClass("shows")
})
}, 500);
});
});
.feed .like-btn {
width: 44px;
height: 25px;
background: #D0D0D0;
position: absolute;
bottom: 13px;
left: 13%;
top: 10%;
cursor: pointer;
}
.feed .like-btn::before {
content: ".";
opacity: 0;
display: block;
width: 44px;
height: 10px;
position: absolute;
top: -10px;
left: 0;
}
.feed .like-btn .reaction-box {
position: absolute;
width: 155px;
height: 55px;
background: #FFF;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
border-radius: 28px;
left: -25px;
bottom: 35px;
display: none;
}
.feed .like-btn .reaction-box .reaction-icon.angry {
animation: fadeInLoad-angry 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px 0px;
}
.feed .like-btn .reaction-box .reaction-icon.flower {
animation: fadeInLoad-flower 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -40px;
}
.feed .like-btn .reaction-box .reaction-icon.haha {
animation: fadeInLoad-haha 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -80px;
}
.feed .like-btn .reaction-box .reaction-icon.like {
animation: fadeInLoad-like 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -120px;
}
.feed .like-btn .reaction-box .reaction-icon.love {
animation: fadeInLoad-love 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -160px;
}
.feed .like-btn .reaction-box .reaction-icon.sad {
animation: fadeInLoad-sad 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -200px;
}
.feed .like-btn .reaction-box .reaction-icon.wow {
animation: fadeInLoad-wow 0.3s;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
background-position: 0px -240px;
}
.feed .like-btn .reaction-box .reaction-icon {
display: inline-block;
width: 40px;
height: 40px;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADEAAAFXCAYAAAALR...
background-size: cover;
border-radius: 20px;
margin: 8px -1px 0 8px;
text-align: center;
pointer-events: none;
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
opacity: 0;
transform: translate(0, 100px) scale(0);
}
.feed .like-btn .reaction-box .reaction-icon label {
padding: 3px 5px 3px 5px;
position: relative;
top: -24px;
border-radius: 10px;
font-size: 11px;
color: #FFF;
background: #333;
visibility: hidden;
}
.feed .like-btn .reaction-box .reaction-icon.shows {
opacity: 1;
transform: translate(0, 0) scale(1);
pointer-events: auto;
}
.feed .like-btn .reaction-box .reaction-icon:hover {
transform: scale(1.4);
transform-origin: bottom;
}
.feed .like-btn .reaction-box .reaction-icon:hover label {
visibility: visible;
}
.feed .like-btn:hover {
background: #718C00;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="feed">
<a class="like-btn" data-rowid="1"> Hover
<div class="reaction-box" data-rowid="1">
<div class="reaction-icon like">
<label>Like</label>
</div>
<div class="reaction-icon love">
<label>Love</label>
</div>
<div class="reaction-icon haha">
<label>Haha</label>
</div>
</div>
</a>
<a class="like-btn" style="margin-top: 50px" data-rowid="2"> Hover
<div class="reaction-box" data-rowid="2">
<div class="reaction-icon like">
<label>Like</label>
</div>
<div class="reaction-icon love">
<label>Love</label>
</div>
<div class="reaction-icon haha">
<label>Haha</label>
</div>
</div>
</a>
<a class="like-btn" style="margin-top...
The given code has some issues that need to be addressed. When hovering over a button, the reactions appear but do not disappear when moving the cursor away from the button. Additionally, if multiple buttons are hovered simultaneously, the animations trigger for all reaction boxes. The desired behavior should be simple: hovering over a button should display its specific reaction, and it should hide when the cursor moves away. This functionality is similar to Facebook's reactions. Furthermore, on mobile devices, the reactions show up on tap, but they should appear on button press (similar to Facebook).