mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-03-13 15:08:09 +00:00
Refactor scroller so that the scrollIntoView() method is a bit more usable
Passing an event instead of a DOM node was silly.
This commit is contained in:
parent
09dbf26ce1
commit
53ead15273
@ -45,7 +45,7 @@ Handle an event
|
||||
*/
|
||||
PageScroller.prototype.handleEvent = function(event) {
|
||||
if(event.type === "tw-scroll") {
|
||||
return this.scrollIntoView(event);
|
||||
return this.scrollIntoView(event.target);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@ -53,20 +53,19 @@ PageScroller.prototype.handleEvent = function(event) {
|
||||
/*
|
||||
Handle a scroll event hitting the page document
|
||||
*/
|
||||
PageScroller.prototype.scrollIntoView = function(event) {
|
||||
PageScroller.prototype.scrollIntoView = function(element) {
|
||||
// Get the offset bounds of the element
|
||||
var domNode = event.target,
|
||||
bounds = {
|
||||
left: domNode.offsetLeft,
|
||||
top: domNode.offsetTop,
|
||||
width: domNode.offsetWidth,
|
||||
height: domNode.offsetHeight
|
||||
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(domNode.offsetParent) {
|
||||
domNode = domNode.offsetParent;
|
||||
bounds.left += domNode.offsetLeft;
|
||||
bounds.top += domNode.offsetTop;
|
||||
while(element.offsetParent) {
|
||||
element = element.offsetParent;
|
||||
bounds.left += element.offsetLeft;
|
||||
bounds.top += element.offsetTop;
|
||||
}
|
||||
// Now get ready to scroll the body
|
||||
this.cancelScroll();
|
||||
|
Loading…
x
Reference in New Issue
Block a user