Fabric JS - Issue in Scrollable Div
Fabric JS - Issue in Scrollable Div
HTML
<script src="https://www.deltalink.it/andreab/fabric/fabric.js"></script>
<canvas id="myCanvas" width="600" height="600"></canvas>
CSS
canvas {
border: 1px solid #999;
}
.imp-modal {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index:1002;
display:block;
background-color: #FFF;
}
.imp-modal .modal-header {
position: absolute;
top: 0;
height: 50px;
width: 100%;
background-color: #f0f0f0;
}
.imp-modal .modal-body {
position: absolute;
top: 50px;
bottom: 50px;
width: 100%;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.imp-modal .modal-footer {
position: absolute;
bottom: 0;
height: 50px;
width: 100%;
background-color: #f0f0f0;
}
.imp-modal .modal-content,
.imp-modal .modal-dialog {
height: 100%;
width: 70%;
}
.imp-modal .close {
opacity: 1;
}
JavaScript
//Friend Image
var fReady = false;
var fImage = new Image();
fImage.onload = function(){
fReady = true;
}
fImage.src="http://vignette1.wikia.nocookie.net/finalfantasy/images/0/0a/FFTS_Fighter_Sprite.png";
var then = 0;
//Game objects
var hero = {
speed:450,
x:200,
y:390
};
var keysDown = {};
addEventListener("keydown", function(e){
keysDown[e.keyCode] = true;
e.preventDefault();
}, false);
addEventListener("keyup", function(e){
delete keysDown[e.keyCode];
e.preventDefault();
}, false);
function update(modifier){
if(38 in keysDown){
hero.y -= hero.speed * modifier;
}
if(40 in keysDown){
hero.y += hero.speed * modifier;
}
if(37 in keysDown){
hero.x -= hero.speed * modifier;
}
if(39 in keysDown){
hero.x += hero.speed * modifier;
}
}
function render(c){
c.clearRect(0,0,600,600)
if(fReady == true){
c.drawImage(fImage,hero.x,hero.y,100,100);
}
}
function setImage(){
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var now = Date.now();
var delta = now-then;
update(delta/100);
render(ctx);
then = now;
requestAnimationFrame(setImage);
}
var w = window;
requestAnimationFrame = w.requestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame || w.mozRequestAnimationFrame;
function start(){
console.log('starting');
then = Date.now();
setImage();
}
start();