0

矢印ボタンをクリックすると、ウィンドウが次の要素にスクロールしますが、下にスクロールしてランダムな要素をクリックすると、最初に前にクリックした要素に戻るか、クリックしない場合は次の要素に移動します。最初の要素。

現在クリックされている要素の横にスクロールしたい。すべてが泡立っています。

私が取り組んでいる、状況が現れるサイト-http://dawidjarzabek.pl/test

jQuery:

var currentElement = $(".post");

$('.post #nav a.prev').click(function() {
    currentElement = currentElement.prev();
    $.scrollTo(currentElement, 800);
});

$('.post #nav a.next').click(function() {
    currentElement = currentElement.next();
    $.scrollTo(currentElement, 800);
});

HTML:

<div id="1" class="section">

    <div class="post position">
        <div id="photo"><center><img src="photos/studio/1.jpg" /></center></div>
        <div id="nav"><a class="prev"><img src="images/icon_top.png" /></a><a class="next"><img src="images/icon_bottom.png" /></a></div>
        <div id="text">
            <h1>Modelka: </h1>
            <h2></h2>
            <h1>Wizaż : </h1>
            <h2></h2>
        </div>
    </div>
    <div class="post position">
        <div id="photo"><center><img src="photos/studio/2.jpg" /></center></div>
        <div id="nav"><a class="prev"><img src="images/icon_top.png" /></a><a class="next"><img src="images/icon_bottom.png" /></a></div>
        <div id="text">
            <h1>Modelka: </h1>
            <h2></h2>
            <h1>Wizaż : </h1>
            <h2></h2>
        </div>
    </div>
</div>

[the rest .post and .section]
4

1 に答える 1

0

これを試して:

$('.post #nav a.prev').click(function() {
    $.scrollTo($(this).closest('.post').prev(),800);
});

$('.post #nav a.next').click(function() {
    $.scrollTo($(this).closest('.post').next(),800);
});

また、変数currentElementを格納する必要はありません。;)

于 2012-08-15T16:36:42.720 に答える