autofit zoom mode implemented
This commit is contained in:
parent
0e3419e7b4
commit
05a93a2a20
1 changed files with 17 additions and 9 deletions
20
scripts.js
20
scripts.js
|
@ -29,10 +29,8 @@ function ComicBook() {
|
|||
var pointer = 0;
|
||||
var loaded = 0;
|
||||
|
||||
var canvas_width;
|
||||
var canvas_height;
|
||||
|
||||
var scale = 1;
|
||||
var zoomMode = "fitWidth"; // manual / fitWidth / fitHeight
|
||||
|
||||
/*
|
||||
* @param {String} id The canvas ID to draw the comic on.
|
||||
|
@ -94,15 +92,25 @@ function ComicBook() {
|
|||
*/
|
||||
function drawPage() {
|
||||
|
||||
var page = pages[pointer];
|
||||
var width, height, page = pages[pointer];
|
||||
|
||||
if (typeof page != "object") throw "invalid page type";
|
||||
|
||||
// update the page scale if a non manual mode has been chosen
|
||||
switch(zoomMode) {
|
||||
case "fitWidth":
|
||||
scale = (window.innerWidth > page.width)
|
||||
? ((window.innerWidth - page.width) / window.innerWidth) + 1 // scale up if the window is wider than the page
|
||||
: window.innerWidth / page.width; // scale down if the window is narrower than the page
|
||||
break;
|
||||
}
|
||||
|
||||
width = page.width * scale;
|
||||
height = page.height * scale;
|
||||
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
// make sure the canvas is always at least full screen, even if the page is more narrow than the screen
|
||||
canvas.width = (height < window.innerWidth) ? window.innerWidth : width;
|
||||
canvas.height = (height < window.innerHeight) ? window.innerHeight : height;
|
||||
|
||||
context.drawImage(page, 0, 0, width, height);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue