简体   繁体   English

Three.js 画布在事件发生后调整大小

[英]Three.js canvas is resizing after events

I'm making mobile-web using three.js.我正在使用three.js制作移动网络。

Also I'm using meta view port tag, <meta name="viewport" content="width=device-width; user-scalable=no; initial-scale:1.0; minimum-scale=1.0; maximum-scale=1.0;" >另外我正在使用元视图端口标签, <meta name="viewport" content="width=device-width; user-scalable=no; initial-scale:1.0; minimum-scale=1.0; maximum-scale=1.0;" > <meta name="viewport" content="width=device-width; user-scalable=no; initial-scale:1.0; minimum-scale=1.0; maximum-scale=1.0;" >

I have a problem that canvas is being resized after raycasting for click event.我有一个问题,即在为单击事件进行光线投射后正在调整画布的大小。

canvas's element.style attribute changed:画布的 element.style 属性改变了:

<canvas width="1081" height="2029" style="width: 980px; height: 1081px;">

into进入

<canvas width="1081" height="2029" style="width: 412px; height: 773px;">

<!--
and changing size is depends on phone's screen size.. for mine is 412 x 773.
-->

I don't know where is changing and setting the canvas style .....我不知道在哪里更改和设置画布style .....

So I added below codes to css,所以我在css中添加了以下代码,

  .canvas{
    width: devicve-width !important;
    height: device-height !important;
  }

  canvas{
    width: devicve-width !important;
    height: device-height !important;
  }

and it doesn't work too.它也不起作用。

Desktop-web is working fine, but only mobile version have the error.桌面网络工作正常,但只有移动版本有错误。

I never reset the canvas's size, I don't know what I have to do.我从不重置画布的大小,我不知道我必须做什么。

Now, I have so many codes ( but there is no codes for re-size the canvas. ), so I'm very confused..现在,我有这么多代码(但没有重新调整画布大小的代码。),所以我很困惑..

Is there any special code in three.js to set canvas's size? Three.js 中是否有任何特殊代码来设置画布的大小?

Or any way to prevent it??或者有什么办法可以防止??

Thank you for your help.感谢您的帮助。

Have a look at the default ThreeJS example.看看默认的 ThreeJS 示例。 The magical lines are the following.神奇的台词如下。

function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
}

You can see how they are used here你可以在这里看到它们是如何使用的

您可以像这样设置 Three.js 画布大小

renderer.setSize(window.innerWidth, window.innerHeight);

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

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