added left/right navigation arrows

This commit is contained in:
Bala Clark 2011-08-30 22:58:31 +02:00
parent b5dcc04f32
commit 2a622f2726
4 changed files with 58 additions and 7 deletions

BIN
img/left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
img/right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -183,14 +183,35 @@ function ComicBook(id, srcs, opts) {
top: "40%", top: "40%",
left: "40%" left: "40%"
}) })
.draggable() .draggable(),
/**
* Page navigation
*/
navigation: {
left: $(document.createElement("div"))
.addClass("control navigate left")
.click(function(e){
ComicBook.prototype.drawPrevPage();
}),
right: $(document.createElement("div"))
.addClass("control navigate right")
.click(function(e) {
ComicBook.prototype.drawNextPage();
})
}
}; };
/** /**
* TODO: center, make sure they never leave the visible portion of the screen * TODO: center, make sure they never leave the visible portion of the screen
*/ */
ComicBook.prototype.renderControls = function() { ComicBook.prototype.renderControls = function() {
$(canvas).after(this.getControl("image").hide()); $(canvas)
.after(this.getControl("navigation").left)
.after(this.getControl("navigation").right)
.after(this.getControl("image").hide());
}; };
ComicBook.prototype.getControl = function(control) { ComicBook.prototype.getControl = function(control) {
@ -263,7 +284,7 @@ function ComicBook(id, srcs, opts) {
// show load status panel // show load status panel
if ($("#status").length === 0) { if ($("#status").length === 0) {
$(canvas).after('<div class="control" id="status"><p></p></div>'); $(canvas).after('<div class="floating control" id="status"><p></p></div>');
} }
// I am using recursion instead of a forEach loop so that the next image is // I am using recursion instead of a forEach loop so that the next image is
@ -352,7 +373,8 @@ function ComicBook(id, srcs, opts) {
: window.innerWidth / width; // scale down if the window is narrower than the page : window.innerWidth / width; // scale down if the window is narrower than the page
break; break;
default:throw "invalid zoomMode"; default:
throw "invalid zoomMode";
} }
var canvas_width = page.width * zoom_scale; var canvas_width = page.width * zoom_scale;
@ -402,6 +424,9 @@ function ComicBook(id, srcs, opts) {
// revert page mode back to double if it was auto switched for a double page spread // revert page mode back to double if it was auto switched for a double page spread
if (is_double_page_spread) { options.displayMode = "double"; } if (is_double_page_spread) { options.displayMode = "double"; }
// resize navigation controls
$(".control.navigate").height(window.innerHeight);
// user callback // user callback
if (typeof options.afterDrawPage === "function") { if (typeof options.afterDrawPage === "function") {
options.afterDrawPage(pointer + 1); options.afterDrawPage(pointer + 1);
@ -550,7 +575,7 @@ function ComicBook(id, srcs, opts) {
e.stopPropagation(); e.stopPropagation();
window.scroll(0,0); // make sure the top of the page is in view window.scroll(0, 0); // make sure the top of the page is in view
// western style (left to right) // western style (left to right)
if (!options.manga) { if (!options.manga) {

View file

@ -9,15 +9,41 @@ body {
} }
.control { .control {
background-color: #000;
color: #fff; color: #fff;
background-color: #111; background-color: #111;
margin: 5px; margin: 5px;
padding: 8px; padding: 8px;
opacity: .9;
}
.control.floating {
-webkit-border-radius: 4px; -webkit-border-radius: 4px;
-moz-border-radius: 4px; -moz-border-radius: 4px;
border-radius: 4px; border-radius: 4px;
opacity: .9; }
.control.navigate {
position: fixed;
top: 0;
cursor: pointer;
width: 128px;
background: center no-repeat;
opacity: 0;
}
.control.navigate:hover {
display: block;
opacity: 1;
}
.control.navigate.left {
left: 0;
background-image: url(img/left.png);
}
.control.navigate.right {
right: 0;
background-image: url(img/right.png);
} }
.ui-draggable { .ui-draggable {