I am facing an issue with an animation that moves in one direction. I am looking to reverse the animation so it goes back to its original position:
$('#right').click(function() {
$('.container').removeClass('.move-left').addClass('move-right');
});
$('#left').click(function() {
$('.container').removeClass('.move-right').addClass('move-left');
});
.container {
margin-top: 20px;
width: 10px; height: 10px;
background-color: green;
}
.move-right {
animation: move-right 10s linear;
}
.move-left {
animation: move-left 10s linear;
}
@keyframes move-right {
to {
transform: translateX(500px);
}
}
@keyframes move-left {
to {
transform: translateX(0);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="left">Left</button>
<button id="right">Right right first</button>
<div class="container"></div>
http://codepen.io/Deka87/pen/GWVbjv
This current solution does not work as expected, likely due to the need to save the current translate
position resulting in unexpected behavior when resizing the page. Is there a more reliable alternative? (Perhaps using `animation-direction`).