When I am hovering on a menu, I'd like an arrow will slide from left to the menu item I'm currently hovering on.
In JavaScript I'd bind an event to hover and play with the arrow element's "left" property, but I wonder if I can have a pure css3 animated solution.
The arrow is similar to this thread- Show border triangle in navbar using CSS
But I don't want it to appear and hide- I want the arrow always visible and that it will slide right to left depending on the menu I'm currently hovering on.
This is how it would look if I'd done it in JS:
var arrEle = $("#indication-mark-wrap");
var startHover = $(arrEle).css("left");
$("li").mouseenter(function() {
var left = $(this).position().left;
$(arrEle).css("left", left+30);
});
$("li").mouseleave(function() {
$(arrEle).css("left", startHover);
});
ul {
list-style-type: none;
padding: 0px;
}
li {
display: inline-block;
width: 80px;
color: white;
background-color: black;
height: 50px;
}
#indication-mark-wrap {
position: absolute;
left: 38px;
top: 56px;
background: wheat;
-webkit-transition: all 1000ms cubic-bezier(0.000, 0.000, 0.330, 0.990);
-moz-transition: all 1000ms cubic-bezier(0.000, 0.000, 0.330, 0.990);
-o-transition: all 1000ms cubic-bezier(0.000, 0.000, 0.330, 0.990);
transition: all 1000ms cubic-bezier(0.000, 0.000, 0.330, 0.990);
/* custom */
-webkit-transition-timing-function: cubic-bezier(0.000, 0.000, 0.330, 0.990);
-moz-transition-timing-function: cubic-bezier(0.000, 0.000, 0.330, 0.990);
-o-transition-timing-function: cubic-bezier(0.000, 0.000, 0.330, 0.990);
transition-timing-function: cubic-bezier(0.000, 0.000, 0.330, 0.990);
/* custom */
}
.indication-mark {
position: relative;
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="menu">
<ul>
<li>Selection1</li>
<li>Selection2</li>
<li>Selection2</li>
</ul>
</div>
<div id="indication-mark-wrap">
<canvas width="20" height="20" class="indication-mark"></canvas>
</div>