mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
parent
fe69b169aa
commit
4c06bd72de
@ -54,15 +54,30 @@ PageScroller.prototype.scrollIntoView = function(event) {
|
|||||||
bounds.left += domNode.offsetLeft;
|
bounds.left += domNode.offsetLeft;
|
||||||
bounds.top += domNode.offsetTop;
|
bounds.top += domNode.offsetTop;
|
||||||
}
|
}
|
||||||
// Now scroll the body
|
// Now get ready to scroll the body
|
||||||
var scrollPosition = $tw.utils.getScrollPosition();
|
|
||||||
this.cancelScroll();
|
this.cancelScroll();
|
||||||
this.startTime = new Date();
|
this.startTime = new Date();
|
||||||
this.startX = scrollPosition.x;
|
var scrollPosition = $tw.utils.getScrollPosition(),
|
||||||
this.startY = scrollPosition.y;
|
// We'll consider the horizontal and vertical scroll directions separately via this function
|
||||||
this.endX = bounds.left;
|
getEndPos = function(targetPos,targetSize,currentPos,currentSize) {
|
||||||
this.endY = bounds.top;
|
// If the target is above/left of the current view, then scroll to it's top/left
|
||||||
if((this.endX < this.startX) || (this.endX > (this.startX + window.innerWidth)) || (this.endY < this.startY) || (this.endY > (this.startY + window.innerHeight))) {
|
if(targetPos <= 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) {
|
||||||
|
return targetPos;
|
||||||
|
// Otherwise, stay where we are
|
||||||
|
} else {
|
||||||
|
return currentPos;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
endX = getEndPos(bounds.left,bounds.width,scrollPosition.x,window.innerWidth),
|
||||||
|
endY = getEndPos(bounds.top,bounds.height,scrollPosition.y,window.innerHeight);
|
||||||
|
// Only scroll if necessary
|
||||||
|
if(endX !== scrollPosition.x || endY !== scrollPosition.y) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.timerId = window.setInterval(function() {
|
this.timerId = window.setInterval(function() {
|
||||||
var t = ((new Date()) - self.startTime) / $tw.config.preferences.animationDuration;
|
var t = ((new Date()) - self.startTime) / $tw.config.preferences.animationDuration;
|
||||||
@ -71,7 +86,7 @@ PageScroller.prototype.scrollIntoView = function(event) {
|
|||||||
t = 1;
|
t = 1;
|
||||||
}
|
}
|
||||||
t = $tw.utils.slowInSlowOut(t);
|
t = $tw.utils.slowInSlowOut(t);
|
||||||
window.scrollTo(self.startX + (self.endX - self.startX) * t,self.startY + (self.endY - self.startY) * t);
|
window.scrollTo(scrollPosition.x + (endX - scrollPosition.x) * t,scrollPosition.y + (endY - scrollPosition.y) * t);
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user