| | Theejs, Responsive | |
| | Author | Message |
---|
phaidonas
Posts : 24 Points : 32 Reputation : 0 Join date : 2017-02-07
| Subject: Theejs, Responsive Tue Feb 07, 2017 6:34 pm | |
| Hello, i want to make my elements responsive,the problem is that i want also to change the width of the mesh and the position of the camera,for now i work with a code like this: if(screen.width<=1280 && screen.width>500){ camera.position.x = -10; camera.position.z = -370;
}else if (screen.width<=500){ camera.position.x = 0; camera.position.z = -75;
}else if (screen.width>1280) { camera.position.x = -70; camera.position.z = -370; } camera.position.x.needsUpdate = true; camera.position.z.needsUpdate = true;
same for the width of the mesh.It works fine except that is not realtime, for the changes to apply i have to refresh the site,i assume that someone will not make inspect and change rather get into the site from a single device at a time,the problem in mobiles or tablets when they turn vertical the device Any suggetions? | |
| | | SamCorny
Posts : 40 Points : 56 Reputation : 0 Join date : 2017-02-06 Location : NYC
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 8:08 pm | |
| I think you should not change or get resolution via javascript but only via CSS. I mean let the CSS do the work of canvas resize: - Code:
-
@media only screen and (min-width: 1280px) { /* Canvas */ } and are you using onWindowResize function? - Code:
-
function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); } | |
| | | phaidonas
Posts : 24 Points : 32 Reputation : 0 Join date : 2017-02-07
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 8:21 pm | |
| I will try it, i have a text in the mesh and it has to be designly correct, when the window resizes | |
| | | SamCorny
Posts : 40 Points : 56 Reputation : 0 Join date : 2017-02-06 Location : NYC
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 8:32 pm | |
| Take a look at a simple "cube example" on threejs.org and look at the function call "onWindowResize" cause it could be your solution. | |
| | | Admin Admin
Posts : 46 Points : 78 Reputation : 3 Join date : 2017-02-06 Location : London, Milan
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 8:49 pm | |
| I will give the capabilities to new users to post links This is an example where you can see what Sam said: Three cube | |
| | | Admin Admin
Posts : 46 Points : 78 Reputation : 3 Join date : 2017-02-06 Location : London, Milan
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 8:49 pm | |
| I will give the capabilities to new users to post links This is an example where you can see what Sam said: Three cube | |
| | | phaidonas
Posts : 24 Points : 32 Reputation : 0 Join date : 2017-02-07
| Subject: Re: Theejs, Responsive Tue Feb 07, 2017 11:24 pm | |
| Ok, but still the mesh doesn't get smaller,the mesh has a standard width and height,it is not window dependant | |
| | | WebForce
Posts : 22 Points : 30 Reputation : 0 Join date : 2017-02-07
| Subject: Re: Theejs, Responsive Wed Feb 08, 2017 9:21 am | |
| Cause you have to change also the DOM in javascript! try this: - Code:
-
var renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth / 2, window.innerHeight / 2 ); document.body.appendChild( renderer.domElement ); renderer.domElement.style.width = renderer.domElement.width * 1 + 'px'; renderer.domElement.style.height = renderer.domElement.height * 1 + 'px';
now it should work | |
| | | Admin Admin
Posts : 46 Points : 78 Reputation : 3 Join date : 2017-02-06 Location : London, Milan
| Subject: Re: Theejs, Responsive Wed Feb 08, 2017 3:21 pm | |
| | |
| | | Sponsored content
| Subject: Re: Theejs, Responsive | |
| |
| | | | Theejs, Responsive | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Our first goal | Mon Feb 27, 2017 10:12 am by Admin | More than 20 users,
almost 150 posts,
a new big project is coming,
about …
| Comments: 0 |
Forum changements | Tue Feb 21, 2017 6:10 pm by Admin | Dear members,
I have personally made some changements into the forum, now …
| Comments: 2 |
A new revision of the forum rules | Tue Feb 07, 2017 9:40 pm by Admin | Dear Members,
it is my pleasure to tell you below all the new functions I …
| Comments: 0 |
Top posting users this week | |
|