mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Scrolling Renderer remove views when they leave the screen
This commit is contained in:
parent
87bd3a68ad
commit
c6465177c5
9 changed files with 371 additions and 175 deletions
|
@ -88,19 +88,18 @@ EPUBJS.Infinite.prototype.check = function(){
|
|||
|
||||
if(this.scrolled && !this.displaying) {
|
||||
|
||||
// var scrollTop = window.pageYOffset || document.documentElement.scrollTop
|
||||
// var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft
|
||||
var scrollTop = this.container.scrollTop;
|
||||
var scrollLeft = this.container.scrollLeft;
|
||||
|
||||
// var scrollTop = document.body.scrollTop;//TODO: make document.body a variable
|
||||
// var scrollHeight = document.documentElement.scrollHeight;
|
||||
var scrollHeight = this.container.scrollHeight;
|
||||
var scrollWidth = this.container.scrollWidth;
|
||||
|
||||
var direction = scrollTop - this.prevScrollTop;
|
||||
var height = this.container.getBoundingClientRect().height;
|
||||
|
||||
var up = height - (scrollHeight - scrollTop) > -this.offset;
|
||||
var up = scrollTop + this.offset > scrollHeight-height;
|
||||
var down = scrollTop < this.offset;
|
||||
|
||||
// console.debug("scroll", scrollTop)
|
||||
if(up && direction > 0) {
|
||||
this.forwards();
|
||||
}
|
||||
|
@ -108,13 +107,32 @@ EPUBJS.Infinite.prototype.check = function(){
|
|||
this.backwards();
|
||||
}
|
||||
|
||||
// console.log(document.body.scrollTop)
|
||||
// console.log(scrollTop)
|
||||
this.prevScrollTop = scrollTop;
|
||||
|
||||
this.scrolled = false;
|
||||
} else {
|
||||
this.displaying = false;
|
||||
this.scrolled = false;
|
||||
}
|
||||
|
||||
this.tick.call(window, this.check.bind(this));
|
||||
}
|
||||
|
||||
EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
|
||||
if(silent) {
|
||||
this.displaying = true;
|
||||
}
|
||||
this.container.scrollLeft += x;
|
||||
this.container.scrollTop += y;
|
||||
};
|
||||
|
||||
EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
|
||||
if(silent) {
|
||||
this.displaying = true;
|
||||
}
|
||||
this.container.scrollLeft = x;
|
||||
this.container.scrollTop = y;
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype);
|
Loading…
Add table
Add a link
Reference in a new issue