mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Make scroller work on Firefox
This commit is contained in:
parent
d0a9bfd0f0
commit
086feb31dc
@ -16,7 +16,7 @@ function slowInSlowOut(t) {
|
|||||||
return (1 - ((Math.cos(t * Math.PI) + 1) / 2));
|
return (1 - ((Math.cos(t * Math.PI) + 1) / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
function animate(animList,duration) {
|
function animateScroll(startX,startY,endX,endY,duration) {
|
||||||
var startTime = new Date(),
|
var startTime = new Date(),
|
||||||
timerId = window.setInterval(function() {
|
timerId = window.setInterval(function() {
|
||||||
var t = ((new Date()) - startTime) / duration;
|
var t = ((new Date()) - startTime) / duration;
|
||||||
@ -25,33 +25,24 @@ function animate(animList,duration) {
|
|||||||
t = 1;
|
t = 1;
|
||||||
}
|
}
|
||||||
t = slowInSlowOut(t);
|
t = slowInSlowOut(t);
|
||||||
for(var a=0; a<animList.length; a++) {
|
var x = startX + (endX - startX) * t,
|
||||||
var anim = animList[a];
|
y = startY + (endY - startY) * t;
|
||||||
document.body[anim.property] = anim.from + (anim.to - anim.from) * t;
|
window.scrollTo(x,y);
|
||||||
}
|
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Check if the top left corner of a given element is currently visible, given the scroll position
|
|
||||||
*/
|
|
||||||
function isVisible(element) {
|
|
||||||
var x = element.offsetLeft, y = element.offsetTop;
|
|
||||||
return (x >= document.body.scrollLeft) &&
|
|
||||||
(x < (document.body.scrollLeft + window.innerHeight)) &&
|
|
||||||
(y >= document.body.scrollTop) &&
|
|
||||||
(y < (document.body.scrollTop + window.innerHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Smoothly scroll an element back into view if needed
|
Smoothly scroll an element back into view if needed
|
||||||
*/
|
*/
|
||||||
function scrollIntoView(element) {
|
function scrollIntoView(element) {
|
||||||
if(!isVisible(element)) {
|
var x = element.offsetLeft,
|
||||||
animate([
|
y = element.offsetTop,
|
||||||
{property: "scrollLeft", from: document.body.scrollLeft, to: element.offsetLeft},
|
winWidth = window.innerWidth,
|
||||||
{property: "scrollTop", from: document.body.scrollTop, to: element.offsetTop}
|
winHeight = window.innerHeight,
|
||||||
],$tw.config.preferences.animationDuration);
|
scrollLeft = window.scrollX || document.documentElement.scrollLeft,
|
||||||
|
scrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||||
|
if((x < scrollLeft) || (x > (scrollLeft + winWidth)) || (y < scrollTop) || (y > (scrollTop + winHeight))) {
|
||||||
|
animateScroll(scrollLeft,scrollTop,x,y,$tw.config.preferences.animationDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user