1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

Switched to Gulp, Basic Scrolling Renderer

This commit is contained in:
Fred Chasen 2014-08-05 23:52:41 -04:00
parent b1b98f9d57
commit d73133e2c7
12 changed files with 4826 additions and 186 deletions

View file

@ -3,23 +3,37 @@ EPUBJS.Infinite = function(container, renderer){
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 = 250;
this.views = [];
this.renderer = renderer;
this.prevScrollTop = 0;
};
EPUBJS.Infinite.prototype.start = function(first_argument) {
window.addEventListener("scroll", function(){
this.scrolled = true;
EPUBJS.Infinite.prototype.start = function() {
var firstScroll = true;
this.container.addEventListener("scroll", function(e){
if(!this.ignore) {
this.scrolled = true;
} else {
this.ignore = false;
}
// console.log("scroll", this.container.scrollTop)
}.bind(this));
// Reset to prevent jump
window.addEventListener('unload', function(e){
this.ignore = true;
// window.scroll(0,0);
});
this.tick.call(window, this.check.bind(this));
// Fill Screen
this.scrolled = false;
};
EPUBJS.Infinite.prototype.forwards = function() {
@ -29,7 +43,6 @@ EPUBJS.Infinite.prototype.forwards = function() {
EPUBJS.Infinite.prototype.backwards = function() {
this.trigger("backwards");
};
/*
@ -75,18 +88,28 @@ EPUBJS.Infinite.prototype.check = function(){
if(this.scrolled && !this.displaying) {
var scrollTop = document.body.scrollTop;//TODO: make document.body a variable
var scrollHeight = document.body.scrollHeight;
// console.log(scrollTop, this.windowHeight - (scrollHeight - scrollTop) )
if(this.windowHeight - (scrollHeight - scrollTop) > -this.offset) {
// var scrollTop = window.pageYOffset || document.documentElement.scrollTop
// var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft
var scrollTop = this.container.scrollTop;
// var scrollTop = document.body.scrollTop;//TODO: make document.body a variable
// var scrollHeight = document.documentElement.scrollHeight;
var scrollHeight = this.container.scrollHeight;
var direction = scrollTop - this.prevScrollTop;
var height = this.container.getBoundingClientRect().height;
var up = height - (scrollHeight - scrollTop) > -this.offset;
var down = scrollTop < this.offset;
if(up && direction > 0) {
this.forwards();
}
else if(scrollTop < this.offset) {
else if(down && direction < 0) {
this.backwards();
}
// console.log(document.body.scrollTop)
this.prevScrollTop = scrollTop;
this.scrolled = false;
}