Skip to content

Instantly share code, notes, and snippets.

@thisgeek
Forked from 34tth3r1ch/healthguide.js
Created August 27, 2012 00:27
Show Gist options
  • Save thisgeek/3484643 to your computer and use it in GitHub Desktop.
Save thisgeek/3484643 to your computer and use it in GitHub Desktop.
jQuery(function() {
var myApi, verts;
// Query for sub-navigation elements. Make each vertically
// scrollable. Save query object as local variable to allow
// methods to be added to the instance.
verts = $(".vertScrollable").each(function(i, e) {
$(e).scrollable({
vertical: true,
prev: ".healthup",
next: ".healthdown"
});
});
// Add resetScroll method to sub-navigation query instance
verts.resetScroll = function () {
this.each(function (i, e) {
$(e).data("scrollable").seekTo(0);
});
};
$("#scrollable").scrollable();
myApi = $("#scrollable").data("scrollable");
// Iterate through a list of class selectors mapped to indicies.
// Bind a click event listener to each element returned by the
// selector query. On click, scroll to the index mapped to the
// selector and reset the subnavigation scrolling to zero.
$.each({
".nutrition": 0,
".fitnessExercise": 1,
".beautySkincare": 2,
".mindfulness": 3,
".quicktips": 4,
".recipes": 5,
".glossary": 6
}, function (selector, index) {
$(selector).click(function () {
myApi.seekTo(index);
verts.resetScroll();
});
});
});
@34tth3r1ch
Copy link

... you're a god.

No, that's not the behavior I had in mind, but I had an idea that would be the case. Would a reset be possible when clicking any of the side navigation elements?

Question, so I understand the issue better: why does scrollable only apply to the first element in the query? I thought since all sidebar navigation was nested within "scrollable," that it would apply to "each" instance...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment