Mehrere Jquery simple Slider auf einer Seite

Erstellt habe ich meine erste Jquery content slider (dots + Folien). Es funktioniert gut, aber ich kann, implementieren Sie zwei Schieberegler auf einer Seite.
Wie rufen Sie die Funktion auf zwei ids?
Ich habe gerade angefangen zu lernen, JS, so brauche ich nur die beiden Potis zum arbeiten, nicht um Sie besser zu machen etc.
Dank

<div class="slider"  id="slider">
    <div class="slides">
                 <!-- ... -->
    </div>
</div>

<div class="slider"  id="slider2">
    <div class="slides">
                    <!-- ... -->
    </div>
</div>

JS

(function($) {
    $.fn.slajder = function() {
        return this.each(function() {

    slider = $(this);
    slider.prepend('<nav class=\"dots"><span></span><span></span></nav>');

    slides = slider.children(".slides");
    dots = slider.children(".dots");
    dot = dots.children("span");
    dot1 = dots.children("span:first-child");
    dot2 = dots.children("span:nth-child(2)");

    dot1.click(function(){
        slides.animate({
            top: '10px',
        }, 600, function() {
        //Animation complete.

        });
        dot.css("-webkit-box-shadow","#444 0 1px 1px 0px");
        $(this).css("-webkit-box-shadow","#444 0 -1px 1px 0px");
    });
    dot2.click(function(){
        slides.animate({
            top: '-130px',
        }, 600, function() {
        //Animation complete.

        });
        dot.css("-webkit-box-shadow","#444 0 1px 1px 0px");
        $(this).css("-webkit-box-shadow","#444 0 -1px 1px 0px");
    });


        });
    };
}(jQuery));

//this one goes at bottom of a page in script tags
$(document).ready(function() {
 $('#slider').slajder();
});

- Und fiddle - http://jsfiddle.net/lima_fil/CK2jS/

  • Die common-Selektor wird der class "slider", so $('.slider').slajder();
InformationsquelleAutor lima_fil | 2013-05-01
Schreibe einen Kommentar