So I got an element with the following CSS:
top: 0;
left: 0;
width: 100%;
height: 300px;
border-radius: 0;
box-shadow: none;
transition: all .3s ease-in-out;
On click I am trying to add/subtract 100%
from the left
property depending on which button is clicked:
$('.next, .prev').click(function() {
if ($(this).hasClass("next")) {
$(".element").animate({
left: '-=100%'
}, 500);
}
else if ($(this).hasClass("prev")) {
$(".element").animate({
left: '+=100%'
}, 500);
}
});
When I click one of the buttons, it works fine, but on the 2nd press, it jumps to a percentage, which doesn't makes sense to me, i.e. 1002.22%
, -802.222
, ...
You got a full example here after clicking an element to open the content.
Does anyone know why it's not acting the way I want to?