Scrollable, Carousel, Slider in jquery without any plugin - the simplest way

kicaj picture kicaj · Mar 9, 2011 · Viewed 9.7k times · Source

I looking-for tutorial about jQuery slider (like scrollable plugin) with cycle animation. Without any plugin, the simplest way, tutorial

Answer

Luca Filosofi picture Luca Filosofi · Mar 9, 2011

UPDATED: 27/08/2014

    $(function() {
        /* author: Luca Filosofi * contact: [email protected] * http://devilmaycode.it * license: Public * Updated: 27/08/2014 */
        var animating = false, iXS = 3, $slider = $('.panel-inner'), liW = $slider.find('li:first').width(), liFW = (liW * $slider.find('li').length);
        $slider.width(liFW);
        $('.button a').on('click', function(e) {
            e.preventDefault();
            if(!animating){
                var left = Math.abs(parseInt($slider.css('left')));
                var side = ($(this).data('direction') == 'right')  ? (((left + (liW * iXS)) >= liFW) ? 0 : -(left + liW)) : ((left > 0) ? -(left - liW) : -(liFW - (liW * iXS)));
                rotate(side);
            }
        });
        var rotate = function(leftY) {
            if(!animating){
                animating = true;
                $slider.stop(true, true).animate({left : leftY}, 500, function(){animating = false;});
            }
        }
    });