Reactjs 保持舞台的高宽比
我试图为Stage元素设置一个纵横比,但没有任何运气 例如,对于画布,我将为风景画编写以下内容: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
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,一切都会很好。我尝试过这样做,但没有效果