mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 17:10:29 +00:00
Use client bounding rect rather than offset positions for computing scroll positions
This commit is contained in:
parent
20f6383528
commit
535837e017
@ -55,25 +55,20 @@ Handle a scroll event hitting the page document
|
||||
*/
|
||||
PageScroller.prototype.scrollIntoView = function(element) {
|
||||
var duration = $tw.utils.getAnimationDuration();
|
||||
// Get the offset bounds of the element
|
||||
var bounds = {
|
||||
left: element.offsetLeft,
|
||||
top: element.offsetTop,
|
||||
width: element.offsetWidth,
|
||||
height: element.offsetHeight
|
||||
};
|
||||
// Walk up the tree adjusting the offset bounds by each offsetParent
|
||||
while(element.offsetParent) {
|
||||
element = element.offsetParent;
|
||||
bounds.left += element.offsetLeft;
|
||||
bounds.top += element.offsetTop;
|
||||
}
|
||||
// Now get ready to scroll the body
|
||||
this.cancelScroll();
|
||||
this.startTime = new Date();
|
||||
var scrollPosition = $tw.utils.getScrollPosition(),
|
||||
// We'll consider the horizontal and vertical scroll directions separately via this function
|
||||
getEndPos = function(targetPos,targetSize,currentPos,currentSize) {
|
||||
var scrollPosition = $tw.utils.getScrollPosition();
|
||||
// Get the client bounds of the element and adjust by the scroll position
|
||||
var clientBounds = element.getBoundingClientRect(),
|
||||
bounds = {
|
||||
left: clientBounds.left + scrollPosition.x,
|
||||
top: clientBounds.top + scrollPosition.y,
|
||||
width: clientBounds.width,
|
||||
height: clientBounds.height
|
||||
};
|
||||
// We'll consider the horizontal and vertical scroll directions separately via this function
|
||||
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) {
|
||||
return targetPos;
|
||||
|
Loading…
Reference in New Issue
Block a user