I'm trying to make my page slides scroll when I click on a link in Javascript / jQuery, but I can't figure out how to pass the current increment value of my for loop as a parameter, in a for that binds click events on my links. When I click, it calls my defined function, but with the current value of my i, and not the value it has when the function was defined... Here's some of my code :
temp[0] = 0;
for(var i = 1; i < 8; i++) {
temp[i] = defaultPositions["slide" + i].top;
console.log(defaultPositions["slide" + i].top);
$('a.slide' + i).bind('click', function() {
$('html, body').animate({scrollTop:(defaultPositions['slide' + i].top / slidesScrollSpeed)}, 1000, function() {
parallaxScroll();
});
return false;
});
}
How can I pass the i value so that when I click on a link, each link has the expected value instead of all being slide8?