简体   繁体   English

JCanvas:具有超大可拖动图像的全屏画布

[英]JCanvas: full screen canvas with oversize draggable image

Using JCanvas, I would like to do two things: 使用JCanvas,我想做两件事:

  1. Define the size of a canvas dynamically according to the width and height of the screen. 根据屏幕的宽度和高度动态定义画布的大小。

  2. Draw an image bigger than the screen to the canvas and make it draggable, with dragging stopping at the edges of the image. 在画布上绘制比屏幕大的图像,使其可拖动,并在图像的边缘停止拖动。

I have the following code: 我有以下代码:

function init() {
    $canvas = $('#canvas');
    $canvas.width = window.innerWidth;
    $canvas.height = window.innerHeight;

    $canvas.drawImage({
        x: 0,
        y: 0,
        source: "../images/testimage.jpg",
        draggable: true,
        layer: true,
    }).drawLayers();
}

Unfortunately, the browser shows only a small section from the center of the image (w: 300 px; h: 150 px) in the upper left corner. 不幸的是,浏览器在左上角仅显示了图像中心的一小部分(w:300像素; h:150像素)。 As far as I can tell, no CSS is involved here. 据我所知,这里没有涉及CSS。

I can drag the image in the small 300 px x 150 px viewport. 我可以在300像素x 150像素的小视口中拖动图像。 However, I want the visible part of the image to be spread over the full screen and dragging to stop a the edges of the screen: no white space shall ever be visible. 但是,我希望图像的可见部分散布在整个屏幕上并拖动以停止屏幕的边缘:永远不会出现空白。

What am I doing wrong? 我究竟做错了什么?

Try 尝试

var canvas = document.getElementById('canvas');
canvas.width = innerWidth;
canvas.height = innerHeight;

As I can never workout what Jquery as it is far from obvious looking at your code. 由于我永远无法锻炼什么Jquery,因此远远看不到您的代码。 If that works then you know that jQuery is setting the style width and height. 如果可行,那么您知道jQuery正在设置样式的宽度和高度。 For the canvas the width and height set the pixel resolution and the canvas.style.width height set the display size. 对于画布,width和height设置像素分辨率,而canvas.style.width height设置显示尺寸。

The default canvas resolution is canvas.width = 300 and canvas.height = 150 默认的画布分辨率为canvas.width = 300canvas.height = 150

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM