Forum Webmastera, HTML, CSS, PHP, MySQL, Hosting, Domeny - Forum dla Webmasterów
jQuery Slider - Wersja do druku

+- Forum Webmastera, HTML, CSS, PHP, MySQL, Hosting, Domeny - Forum dla Webmasterów (https://www.webmastertalk.pl)
+-- Dział: Technologie internetowe - tworzenie stron WWW (https://www.webmastertalk.pl/forum-technologie-internetowe-tworzenie-stron-www)
+--- Dział: xHTML, CSS, JavaScript (https://www.webmastertalk.pl/forum-xhtml-css-javascript)
+--- Wątek: jQuery Slider (/thread-jquery-slider)



jQuery Slider - benny - 27-04-2011

Witam,

Mam pytanie odnośnie slidera zrobionego w jquery.
Pobrałem kod z jakiegoś przykładu i działać działa, ale chciałbym zrobić to tak, że po dojściu do końca, nie trzeba przewijać do tyłu, tylko klikając next, będą się powtarzały "opcje" od początku. Chciałbym to tak zrobić, ale nie potrafię, ponieważ jquery łyknąłem dopiero może tydzień temu. Bardzo więc proszę o porady, pewnie dla zaawansowanych nie będzie to stanowiło problemu.

Oto kod:
Kod:
$(document).ready(function() {
        var $sliders = $('.slider');
        $sliders.each(function() {
            var $current_slider = $(this);
            var $lista = $('.lista', $current_slider);
            var $li = $lista.children('li');
            if ($li.length > 3) {
                var odleglosc = $li.eq(0).outerWidth() + parseInt($li.eq(0).css('margin-left')) + parseInt($li.eq(0).css('margin-right'));
                var maxLeft = odleglosc * $li.length - 3 * odleglosc;
                $('.next', $current_slider).click(function() {
                    if ($lista.position().left > -maxLeft) {
                        $($lista).not(':animated').animate({
                            'left' : '-=' + odleglosc
                        },500);
                    }
                });
                $('.prev', $current_slider).click(function() {
                    if ($lista.position().left<0) {
                        $($lista).not(':animated').animate({
                            'left' : '+=' + odleglosc
                        },500);
                    }
                });
            } else {
                $('.next, .prev', $current_slider).click(function() {
                    $(this).preventDefault();
                    return false;
                });
            }
        });
    });



RE: jQuery Slider - Kartofelek - 27-04-2011

if ($lista.position().left > -maxLeft) {
$($lista).not(':animated').animate({
'left' : '-=' + odleglosc
},500);
}

na

if ($lista.position().left > -maxLeft) {
$($lista).not(':animated').animate({
'left' : '-=' + odleglosc
},500);
} else {
$($lista).not(':animated').animate({'left':0},500);
}

a jak to ci nie wystarczy to infinite carusel:
http://doman.art.pl/kursjs/kurs/jquery/plugin.html


RE: jQuery Slider - benny - 27-04-2011

Wielkie dzięki!