Reputation: 732
So, jScrollPane is awesome. Very awesome. It has a whole ton of options and API calls one could make to customize the hell out of it. I'm currently using it to scroll some content on my page and would like to use scrollToElement to position my selected id element in the center. Unfortunately, that's not a param I can pass to scrollToElement. It currently only allows (elem, stickToTop, animate).
Has anyone extended the plugin to allow a stickToCenter param? Trying to save myself time here by not recreating something someone might have already done.
Thanks in advance!
Upvotes: 0
Views: 1532
Reputation: 732
Well, I made my attempt at adding the feature:
The following updates were made to the full version of the plugin (http://jscrollpane.kelvinluck.com/script/jquery.jscrollpane.js):
Line 788:
function scrollToElement(ele, stickToTop, stickToMiddle, middleOffset, animate)
Lines 822, 823
Added another conditional that searches for the stickToMiddle param and applies the middleOffset:
else if (eleTop < viewportTop || stickToMiddle) { destY = (eleTop - settings.verticalGutter) - middleOffset;
Line 895
scrollToElement(e.target, false, false, null);
Line 1034
scrollToElement(e, true, false, null);
Line 1042:
scrollToElement(e, true, false, null);
Line 1102
jsp.scrollToElement(element, true, false, null);
Line 1211
scrollToElement: function(ele, stickToTop, stickToMiddle, middleOffset, animate)
Line 1213
scrollToElement(ele, stickToTop, stickToMiddle, middleOffset, animate);
Having done this, I can now use it like this when making API calls:
api.scrollToElement('#elem', false, true, 115);
Hope this ends up helping someone looking for the same feature. Please update the above as necessary and hopefully this gets added in a future update.
Upvotes: 3