mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +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) {
|
PageScroller.prototype.scrollIntoView = function(element) {
|
||||||
var duration = $tw.utils.getAnimationDuration();
|
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
|
// Now get ready to scroll the body
|
||||||
this.cancelScroll();
|
this.cancelScroll();
|
||||||
this.startTime = new Date();
|
this.startTime = new Date();
|
||||||
var scrollPosition = $tw.utils.getScrollPosition(),
|
var scrollPosition = $tw.utils.getScrollPosition();
|
||||||
// We'll consider the horizontal and vertical scroll directions separately via this function
|
// Get the client bounds of the element and adjust by the scroll position
|
||||||
getEndPos = function(targetPos,targetSize,currentPos,currentSize) {
|
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 the target is above/left of the current view, then scroll to it's top/left
|
||||||
if(targetPos <= currentPos) {
|
if(targetPos <= currentPos) {
|
||||||
return targetPos;
|
return targetPos;
|
||||||
|
Loading…
Reference in New Issue
Block a user