mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Added basic pagination
This commit is contained in:
parent
1a89a9c3ff
commit
816880d328
12 changed files with 1289 additions and 373 deletions
|
@ -1,13 +1,14 @@
|
|||
EPUBJS.Infinite = function(container, renderer){
|
||||
EPUBJS.Infinite = function(container, axis){
|
||||
this.container = container;
|
||||
this.windowHeight = window.innerHeight;
|
||||
this.tick = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
|
||||
this.scrolled = false;
|
||||
this.ignore = false;
|
||||
this.displaying = false;
|
||||
this.offset = 350;
|
||||
this.offset = 900;
|
||||
this.views = [];
|
||||
this.renderer = renderer;
|
||||
this.axis = axis;
|
||||
// this.renderer = renderer;
|
||||
this.prevScrollTop = 0;
|
||||
};
|
||||
|
||||
|
@ -49,12 +50,25 @@ EPUBJS.Infinite.prototype.check = function(){
|
|||
|
||||
if(this.scrolled && !this.displaying) {
|
||||
|
||||
if(this.axis === "vertical") {
|
||||
this.checkTop();
|
||||
} else {
|
||||
this.checkLeft();
|
||||
}
|
||||
|
||||
this.scrolled = false;
|
||||
} else {
|
||||
this.displaying = false;
|
||||
this.scrolled = false;
|
||||
}
|
||||
|
||||
this.tick.call(window, this.check.bind(this));
|
||||
}
|
||||
|
||||
EPUBJS.Infinite.prototype.checkTop = function(){
|
||||
|
||||
var scrollTop = this.container.scrollTop;
|
||||
var scrollLeft = this.container.scrollLeft;
|
||||
|
||||
var scrollHeight = this.container.scrollHeight;
|
||||
var scrollWidth = this.container.scrollWidth;
|
||||
|
||||
var direction = scrollTop - this.prevScrollTop;
|
||||
var height = this.container.getBoundingClientRect().height;
|
||||
|
||||
|
@ -73,14 +87,36 @@ EPUBJS.Infinite.prototype.check = function(){
|
|||
// console.log(scrollTop)
|
||||
this.prevScrollTop = scrollTop;
|
||||
|
||||
this.scrolled = false;
|
||||
} else {
|
||||
this.displaying = false;
|
||||
this.scrolled = false;
|
||||
}
|
||||
return scrollTop;
|
||||
};
|
||||
|
||||
this.tick.call(window, this.check.bind(this));
|
||||
}
|
||||
EPUBJS.Infinite.prototype.checkLeft = function(){
|
||||
|
||||
var scrollLeft = this.container.scrollLeft;
|
||||
|
||||
var scrollWidth = this.container.scrollWidth;
|
||||
|
||||
var direction = scrollLeft - this.prevscrollLeft;
|
||||
|
||||
var width = this.container.getBoundingClientRect().width;
|
||||
|
||||
var right = scrollLeft + this.offset > scrollWidth-width;
|
||||
var left = scrollLeft < this.offset;
|
||||
|
||||
// Add to bottom
|
||||
if(right && direction > 0) {
|
||||
this.forwards();
|
||||
}
|
||||
// Add to top
|
||||
else if(left && direction < 0) {
|
||||
this.backwards();
|
||||
}
|
||||
|
||||
// console.log(scrollTop)
|
||||
this.prevscrollLeft = scrollLeft;
|
||||
|
||||
return scrollLeft;
|
||||
};
|
||||
|
||||
EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
|
||||
if(silent) {
|
||||
|
@ -88,6 +124,9 @@ EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
|
|||
}
|
||||
this.container.scrollLeft += x;
|
||||
this.container.scrollTop += y;
|
||||
|
||||
this.scrolled = true;
|
||||
this.check();
|
||||
};
|
||||
|
||||
EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
|
||||
|
@ -96,6 +135,9 @@ EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
|
|||
}
|
||||
this.container.scrollLeft = x;
|
||||
this.container.scrollTop = y;
|
||||
|
||||
this.scrolled = true;
|
||||
this.check();
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype);
|
Loading…
Add table
Add a link
Reference in a new issue