how to set three js canvas width 100%
JavaScript
body { margin: 0; }
canvas { width: 100vw; height: 100vh; display: block; }"use strict";
const renderer = new THREE.WebGLRenderer();
document.body.appendChild(renderer.domElement);
// There's no reason to set the aspect here because we're going
// to set it every frame anyway so we'll set it to 2 since 2
// is the the aspect for the canvas default size (300w/150h = 2)
const camera = new THREE.PerspectiveCamera(70, 2, 1, 1000);
camera.position.z = 400;
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry(200, 200, 200);
const material = new THREE.MeshPhongMaterial({
color: 0x555555,
specular: 0xffffff,
shininess: 50,
shading: THREE.SmoothShading
});
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
const light1 = new THREE.PointLight(0xff80C0, 2, 0);
light1.position.set(200, 100, 300);
scene.add(light1);
function resizeCanvasToDisplaySize() {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
if (canvas.width !== width ||canvas.height !== height) {
// you must pass false here or three.js sadly fights the browser
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
// set render target sizes here
}
}
function animate(time) {
time *= 0.001; // seconds
resizeCanvasToDisplaySize();
mesh.rotation.x = time * 0.5;
mesh.rotation.y = time * 1;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
Also in JavaScript:
- Title
- can we add new state property using setstate in react
- Category
- JavaScript
- Title
- average of an array js
- Category
- JavaScript
- Title
- javascript add nd st th to number
- Category
- JavaScript
- Title
- getting the value of pi in javascript
- Category
- JavaScript
- Title
- fetch api react
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- foreach w3schools javascript
- Category
- JavaScript
- Title
- javascript check if argument is passed
- Category
- JavaScript
- Title
- How to make string shorter javascript
- Category
- JavaScript
- Title
- como criar uam seessão com jsp
- Category
- JavaScript
- Title
- disable a button react
- Category
- JavaScript
- Title
- how to make all lowercase in js
- Category
- JavaScript
- Title
- copy to clipboard javascript
- Category
- JavaScript
- Title
- button not clicking for random jokes in javascript
- Category
- JavaScript
- Title
- array of images javascript
- Category
- JavaScript
- Title
- arrow function
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- javascript array.find
- Category
- JavaScript
- Title
- ipv4 to int32 js
- Category
- JavaScript
- Title
- is var is not blank then display value in javascript
- Category
- JavaScript
- Title
- dropzone csrf codeigniter
- Category
- JavaScript
- Title
- how to disable cash through get request in angular
- Category
- JavaScript
- Title
- combine values of address line 1 and address line 2 javascript
- Category
- JavaScript
- Title
- angular routing url params
- Category
- JavaScript
- Title
- headroom js react
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- client side redirect javascript
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- get element by class
- Category
- JavaScript
- Title
- find particular object from array in js
- Category
- JavaScript
- Title
- how to add an array to another array in javascript
- Category
- JavaScript
- Title
- How to include JSPs file from another folder
- Category
- JavaScript
- Title
- find duplicates in array of objects javascript
- Category
- JavaScript
- Title
- discord js channel count
- Category
- JavaScript
- Title
- how to send an alert in javascript
- Category
- JavaScript
- Title
- jalali moment get milisocnds
- Category
- JavaScript
- Title
- check if function exists javascript
- Category
- JavaScript
- Title
- how to write and read a text file in jdiscord.js
- Category
- JavaScript
- Title
- how to make a inventory in js
- Category
- JavaScript
- Title
- javascript add class to element
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- are you sure javascript
- Category
- JavaScript
- Title
- how to transpose json data
- Category
- JavaScript
- Title
- Better Array check with Array.isArray Because arrays are not true array in JavaScript, there is no simple typeof check. No problem! Use the method Array.isArray to check…
- Category
- JavaScript
- Title
- bootstrap datepicker can be less than start date
- Category
- JavaScript
- Title
- javascript change class of item
- Category
- JavaScript
- Title
- how to return a string x amount in javascript without using . repeat
- Category
- JavaScript
- Title
- get hash js
- Category
- JavaScript
- Title
- how to change a string to number in javascript
- Category
- JavaScript
- Title
- angular 6 reload current page
- Category
- JavaScript
- Title
- express get url parameters
- Category
- JavaScript
- Title
- execute js with innerhtml
- Category
- JavaScript
- Title
- javascript append to array
- Category
- JavaScript
- Title
- data binding on checkbox angular
- Category
- JavaScript
- Title
- declarar una funcion javascript
- Category
- JavaScript
- Title
- javascript character ascii value modify
- Category
- JavaScript
- Title
- array matching
- Category
- JavaScript
- Title
- javascript cahnge colour of strokerect
- Category
- JavaScript
- Title
- CSRF token in js
- Category
- JavaScript
- Title
- get day js
- Category
- JavaScript
- Title
- how to convert audio blocb to base64 string
- Category
- JavaScript
- Title
- check to see if number is a decimal javascript
- Category
- JavaScript
- Title
- how to send get request to external server using node
- Category
- JavaScript
- Title
- add bootstrap to gatsby
- Category
- JavaScript
- Title
- install vue js
- Category
- JavaScript
- Title
- Elements in iteration expect to have 'v-bind:key' directives
- Category
- JavaScript
- Title
- anime.js morph svg d value
- Category
- JavaScript
- Title
- Bots server count discord js
- Category
- JavaScript
- Title
- javascript change meta tag
- Category
- JavaScript
- Title
- get selected option value
- Category
- JavaScript
- Title
- how to check if a string has only alphabets in javascript
- Category
- JavaScript
- Title
- get value of all checked boxes jquery
- Category
- JavaScript
- Title
- how to make input type date supported on all browsers
- Category
- JavaScript
- Title
- get contents between tags javascript
- Category
- JavaScript
- Title
- discord.js clear code
- Category
- JavaScript
- Title
- eslint ignore javascript
- Category
- JavaScript
- Title
- format number thousands k javascript
- Category
- JavaScript
- Title
- how to compare strings javascript
- Category
- JavaScript
- Title
- create react component class
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- ckeditor change value
- Category
- JavaScript
- Title
- get value from textbox in vanilla javascript
- Category
- JavaScript
- Title
- express() vs express.router()
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- Cannot set property 'innerHTML' of null
- Category
- JavaScript
- Title
- clone aJavaScript object
- Category
- JavaScript
- Title
- check node version
- Category
- JavaScript
- Title
- how to find the index of a value in an array in javascript
- Category
- JavaScript
- Title
- javascript bootstrap ontab change
- Category
- JavaScript
- Title
- if you run a script.js with the code, how do you access the value passed to "var" inside script.js ...
- Category
- JavaScript
- Title
- empty array js
- Category
- JavaScript
- Title
- javascript add to object
- Category
- JavaScript
- Title
- discord.js
- Category
- JavaScript
- Title
- firebase app named default already exists react native
- Category
- JavaScript
- Title
- ajax with progress bar
- Category
- JavaScript
- Title
- create child element in javascript
- Category
- JavaScript
- Title
- How to check if a member has a role discord.js
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- get random item from array javascript
- Category
- JavaScript
- Title
- javascript class click event
- Category
- JavaScript