Only scroll to top when tiddlers are completely off-screen

Fixes #1526
This commit is contained in:
Jermolene 2015-02-25 19:01:40 +00:00
parent b13d87fdf2
commit 489bc7a50b
2 changed files with 9 additions and 5 deletions

View File

@ -68,15 +68,19 @@ PageScroller.prototype.scrollIntoView = function(element) {
height: clientBounds.height
};
// We'll consider the horizontal and vertical scroll directions separately via this function
// targetPos/targetSize - position and size of the target element
// currentPos/currentSize - position and size of the current scroll viewport
// returns: new position of the scroll viewport
var getEndPos = function(targetPos,targetSize,currentPos,currentSize) {
// If the target is above/left of the current view, then scroll to it's top/left
if(targetPos <= currentPos) {
console.log("getEndPos",targetPos,targetSize,currentPos,currentSize)
// If the target is entirely above/left of the current view, then scroll to its top/left
if((targetPos + targetSize) <= currentPos) {
return targetPos;
// If the target is smaller than the window and the scroll position is too far up, then scroll till the target is at the bottom of the window
} else if(targetSize < currentSize && currentPos < (targetPos + targetSize - currentSize)) {
return targetPos + targetSize - currentSize;
// If the target is big, then just scroll to the top
} else if(currentPos < targetPos) {
// If the target is out of view below/right, then just scroll to the top/left
} else if(targetPos > (currentPos + currentSize)) {
return targetPos;
// Otherwise, stay where we are
} else {

View File

@ -1,3 +1,3 @@
title: $:/view
stacked
classic