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,17 +142,27 @@
} }
}); });
// 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({ $('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){ onmatch: function(){
var self = this, var self = this,
panel = self.parents('.cms-panel-content'); panel = self.parents('.cms-panel-content'),
scrollTo;
panel.animate({ if(self.offset().top < 0 ||
scrollTop: self.offset().top - (panel.height() / 2) self.offset().top > panel.height() - self.height()) {
}, 'slow'); // 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: scrollTo
}, 'slow');
}
}
});
}); });
}(jQuery)); }(jQuery));