1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00
epub.js/fpjs/hooks/smartimages.js

43 lines
970 B
JavaScript

FP.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
var image = chapter.doc.querySelectorAll('img'),
items = Array.prototype.slice.call(image),
iheight = chapter.iframe.height,
oheight;
items.forEach(function(item){
function size() {
var itemRect = item.getBoundingClientRect(),
height = itemRect.height,
top = itemRect.top;
iheight = chapter.iframe.height;
if(height + top >= iheight) {
if(top < iheight/2) {
item.style.maxHeight = iheight - top + "px";
}else{
item.style.maxHeight = (height < iheight ? height : iheight) + "px";
item.style.marginTop = iheight - top + "px";
}
}else{
item.style.removeProperty('max-height');
item.style.removeProperty('margin-top');
}
}
chapter.book.listenUntil("book:resized", "book:chapterDestroy", size);
size();
});
if(callback) callback();
}