atulquest93 atulquest93 - 1 year ago 77
HTML Question

Hold Hover event

I;m using this hover-css-items to animate menu.

Particularly : Background Transitions > Swipe to right.

enter image description here

I need to hold the animation like in pic 2 while i leave the button (By default it will come to image 1 if i hover out).

Initially the link is red... and on hover it animates to green ... and on hover out it comes back to red.
I need to keep the link to green even if i hover out ... and externally trigger to go back to red.. when required by changing class.

.hvr-sweep-to-right {
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
.hvr-sweep-to-right:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: green;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: 0 50%;
transform-origin: 0 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
.hvr-sweep-to-right:hover, .hvr-sweep-to-right:focus, .hvr-sweep-to-right:active {
color: white;
.hvr-sweep-to-right:hover:before, .hvr-sweep-to-right:focus:before, .hvr-sweep-to-right:active:before {
-webkit-transform: scaleX(1);
transform: scaleX(1);


<li class="try hvr-sweep-to-right"> Link 1</li>

<li class="try hvr-sweep-to-right"> Link 2 </li>

Answer Source

Try this, you will get the idea:

div {
  width: 100px;
  padding: 11px 16px;
  text-align: center;
  float: left;
  background: #ff3232;
  /* Old browsers */
  background: linear-gradient(to left, red 50%, blue 50%);
  background-size: 200% 100%;
  background-position: right bottom;
  margin-left: 10px;
  transition: all 2s ease;
div:hover {
  background-position: top left;