I am making a carousel of several objects. It is assumed that it will rotate the carousel, so the next object is in focus when I press the next / previous buttons. The first time I press one of the buttons, it slowly enlivens the rotation, but with the following clicks, for some reason, it simply changes the object without animation. And it should be animated every time I click, but it only does it the first time after every page reloads.
Here is jsfiddle: https://jsfiddle.net/sxybreak/jouevx28/1/
Here is my code:
$(document).ready(function() {
var angle;
var i = 0;
$("#previous").on('click', function() {
i+=1;
$("#carousel").animate({borderSpacing: 40}, {
duration: 'slow',
step: function(now, fx) {
$(this).css({
'transform': 'rotateY(' + (i*now) + 'deg)',
'-webkit-transform': 'rotateY(' + (i*now) + 'deg)',
'-moz-transform': 'rotateY(' + (i*now) + 'deg)',
'-ms-transform': 'rotateY(' + (i*now) + 'deg)' });
}
});
});
$("#next").click(function() {
i-=1;
$("#carousel").animate({borderSpacing: 40}, {
duration: 'slow',
step: function(now, fx) {
$(this).css({
'transform': 'rotateY(' + (i*now) + 'deg)',
'-webkit-transform': 'rotateY(' + (i*now) + 'deg)',
'-moz-transform': 'rotateY(' + (i*now) + 'deg)',
'-ms-transform': 'rotateY(' + (i*now) + 'deg)' });
}
});
});
});
source
share