I’m using scrollto, and I’m wanting to have a class added when it scrolls to the next div. Using removeClass/addClass would work? I don’t know where I would place it so when scrollto, scrolls to the current .column div it adds the “selected” class as well.
Coles notes version: I’m looking to the current div highlighted when scrolled to.
This is the scrollto code I’m using:
function scrollToPosition(element) {
if (element !== undefined) {
$(".wrap").scrollTo(element, 800, {
margin: true
});
}
}
$(function() {
//Create an Array of posts
var posts = $('.column');
var position = 0; //Start Position
var next = $('#rightControl');
var prev = $('#leftControl').hide();
//Better performance to use Id selectors than class selectors
next.click(function(evt) {
//Scroll to next position
prev.show();
scrollToPosition(posts[position += 1]);
if (position === posts.length - 1) {
next.hide();
}
});
prev.click(function(evt) {
//Scroll to prev position
next.show();
scrollToPosition(posts[position -= 1]);
if (position === 0) {
prev.hide();
}
});
});
HTML:
<div id="menu"></div>
<div class="arrows">
<div class="nav_arrow">
<div class="control" id="leftControl"></div>
<div class="control" id="rightControl"></div>
</div>
</div>
<div class="wrap">
<div class="content">
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
</div>
</div>
try this untested code!