Implementierung von jQuery .next() in eine einfache Bild-dia-show

jsFiddle ist hier: http://jsfiddle.net/qBQD4/

Es ist ziemlich einfach wirklich, ich will den Pfeil, um die Bilder vorwärts, Pfeil nach Links, verschieben Sie Sie nach hinten in eine einfache Diashow. Ich habe mehrere Diashows laufen auf der Seite, die diesen code umgesetzt wird, also warum ich gegangen bin .die next () - route anstatt nur die Angabe eines eindeutigen div-id. Der HTML-Code:

<div class="media">
    <div class="slideButtons">
        <span class="prev"><</span>
        <span class="next">/></span>
    </div>
    <ul class="gallery" id="olympGallery">
        <li><img src="http://i.imgur.com/8aA7W.jpg" alt="" title="" /></li>
        <li><img src="http://i.imgur.com/jE7vj.jpg" alt="" title="" /></li>
        <li><img src="http://i.imgur.com/L7lVg.jpg" alt="" /></li>
    </ul>
</div>

Und der jQuery-code ist:

var speed = 100;

$(".prev").click(function() {
    var now = $(this).next("ul.gallery").children(":visible"),
        last = $(this).next("ul.gallery").children(":last"),
        prev = now.prev();
        prev = prev.index() == -1 ? last : prev;
    now.fadeOut(speed, function() {prev.fadeIn(speed);});
});

$(".next").click(function() {
    var now = $(this).next("ul.gallery").children(':visible'),
        first = $(this).next("ul.gallery").children(':first'),
        next = now.next();
        next = next.index() == -1 ? first : next;
    now.fadeOut(speed, function() {next.fadeIn(speed);});
});

$(".gallery li").click(function() {
    var first = $(this).parent().children(':first'),
        next = $(this).next();
        next = next.index() == -1 ? first : next;
    $(this).fadeOut(speed, function() {next.fadeIn(speed);});
});    

Und schließlich, ein bisschen CSS:

.prev, .next {position: relative; padding: 3px; font-size:50px; font-weight: 900; cursor:pointer;
}

.gallery li{display:none; list-style:none;}
.gallery li:first-child {display:block;}

.gallery img {
    max-height:550px
}

Den 3. Funktion einwandfrei (ein Klick auf das Bild fortschreitet, um die nächste in der Reihe). Allerdings, die ersten beiden sind völlig gebrochen. Was habe ich falsch gemacht hier?

InformationsquelleAutor JVG | 2012-01-04

Schreibe einen Kommentar