When I click an arrow button, a window scrolls to the next element, but when I scroll down and click a random element, it would first go back to the element I clicked before, or, if I don’t click, it goes to the first element.
I want it to scroll next to current clicked element. Everything is bubbling.
The site I working on, where the situation appears – 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]
Try this:
And you don’t have to store variable currentElement. 😉