mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Account for body offset in iframe view size calculations
This commit is contained in:
parent
864851ab88
commit
96a62d2d00
1 changed files with 14 additions and 2 deletions
|
@ -144,6 +144,7 @@ class Contents {
|
||||||
* @returns {number} width
|
* @returns {number} width
|
||||||
*/
|
*/
|
||||||
textWidth() {
|
textWidth() {
|
||||||
|
let rect;
|
||||||
let width;
|
let width;
|
||||||
let range = this.document.createRange();
|
let range = this.document.createRange();
|
||||||
let content = this.content || this.document.body;
|
let content = this.content || this.document.body;
|
||||||
|
@ -153,7 +154,12 @@ class Contents {
|
||||||
range.selectNodeContents(content);
|
range.selectNodeContents(content);
|
||||||
|
|
||||||
// get the width of the text content
|
// get the width of the text content
|
||||||
width = range.getBoundingClientRect().width;
|
rect = range.getBoundingClientRect();
|
||||||
|
width = rect.width;
|
||||||
|
|
||||||
|
if (this.content === this.document.body && rect.left) {
|
||||||
|
width += rect.left;
|
||||||
|
}
|
||||||
|
|
||||||
if (border && border.width) {
|
if (border && border.width) {
|
||||||
width += border.width;
|
width += border.width;
|
||||||
|
@ -167,6 +173,7 @@ class Contents {
|
||||||
* @returns {number} height
|
* @returns {number} height
|
||||||
*/
|
*/
|
||||||
textHeight() {
|
textHeight() {
|
||||||
|
let rect;
|
||||||
let height;
|
let height;
|
||||||
let range = this.document.createRange();
|
let range = this.document.createRange();
|
||||||
let content = this.content || this.document.body;
|
let content = this.content || this.document.body;
|
||||||
|
@ -174,7 +181,12 @@ class Contents {
|
||||||
|
|
||||||
range.selectNodeContents(content);
|
range.selectNodeContents(content);
|
||||||
|
|
||||||
height = range.getBoundingClientRect().height;
|
rect = range.getBoundingClientRect();
|
||||||
|
height = rect.height;
|
||||||
|
|
||||||
|
if (this.content === this.document.body && rect.top) {
|
||||||
|
height += rect.top;
|
||||||
|
}
|
||||||
|
|
||||||
if (height && border.height) {
|
if (height && border.height) {
|
||||||
height += border.height;
|
height += border.height;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue