Calculate where to scroll to based off the position in the div

Also, only scroll if not currently visible.
This commit is contained in:
Simon Welsh 2013-10-10 15:42:49 +13:00
parent c3e25e9e07
commit 0c2514d13e

View File

@ -142,16 +142,26 @@
}
});
// Scroll tree down to context of the current page
// Scroll tree down to context of the current page, if it isn't
// already visible
$('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){
var self = this,
panel = self.parents('.cms-panel-content');
panel = self.parents('.cms-panel-content'),
scrollTo;
if(self.offset().top < 0 ||
self.offset().top > panel.height() - self.height()) {
// Current scroll top + our current offset top is our
// position in the panel
scrollTo = panel.scrollTop() + self.offset().top
+ (panel.height() / 2);
panel.animate({
scrollTop: self.offset().top - (panel.height() / 2)
scrollTop: scrollTo
}, 'slow');
}
}
});
});