Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 保持舞台的高宽比_Reactjs_Konvajs_Konvajs Reactjs - Fatal编程技术网

Reactjs 保持舞台的高宽比

Reactjs 保持舞台的高宽比,reactjs,konvajs,konvajs-reactjs,Reactjs,Konvajs,Konvajs Reactjs,我试图为Stage元素设置一个纵横比,但没有任何运气 例如,对于画布,我将为风景画编写以下内容: const dpr = window.devicePixelRatio || 1 const aspectRatio = 16 / 9 const canvasHeight = 1080 * dpr; const canvasWidth = 1920 * dpr; <canvas height={canvasHeight} width={canvasHeight * aspect

我试图为Stage元素设置一个纵横比,但没有任何运气

例如,对于画布,我将为风景画编写以下内容:

const dpr = window.devicePixelRatio || 1
const aspectRatio = 16 / 9
const canvasHeight = 1080 * dpr;
const canvasWidth = 1920 * dpr;

<canvas 
  height={canvasHeight} 
  width={canvasHeight * aspectRatio}
  style={{
    maxWidth: '100%',
    maxHeight: '100%
  }}
/>
const dpr=window.devicePixelRatio|1
常量aspectRatio=16/9
常量画布高度=1080*dpr;
常量画布宽度=1920*dpr;

您可以对后台容器执行相同的操作:

const aspectRatio=16/9
常量画布高度=1080;
常量画布宽度=1920;
如果要将阶段容器装入父容器,因此需要100%的父元素,可以执行以下操作:

const parentWidth=parentContainer.offsetwidth;
常量aspectRatio=16/9
常量画布高度=1080;
常量画布宽度=1920;
常量比例=父宽度/画布宽度;

我认为Konva处理fir阶段大小的方式是,它填充您链接到的容器div。因此,将纵横比计算应用于该容器div,一切都会很好。我尝试过这样做,但没有效果