# Three.js screen width

**URL:** <https://discourse.threejs.org/t/three-js-screen-width/20302>\
**Category:** Questions\
**Tags:** math\
**Created:** [October 30, 2020, 2:22pm UTC](https://discourse.threejs.org/t/three-js-screen-width/20302 "2020-10-30T14:22:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lighty](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lighty/32/43283_2.png) [@Lighty](https://discourse.threejs.org/u/Lighty)\
**Post date:** [October 30, 2020, 2:22pm UTC](https://discourse.threejs.org/t/three-js-screen-width/20302/1 "2020-10-30T14:22:42Z")

</div>

I have code

```javascript
let ADD = 0.01;

const animate = function () {
     requestAnimationFrame( animate );
     mesh.position.x += ADD;
         if (mesh.position.x <= -3 || mesh.position.x >= 3) {
          ADD *= -1;
     }
     renderer.render( scene, camera );
};

```

in this example my mesh moves to the left 3 and to the right 3 but i need move mesh to full width. if console.log(window.innerWidth) = 2560(my resolution)

How can i get screen width in space three.js ?

https://codepen.io/Lighty/embed/preview/GRqxvZV?height=300&slug-hash=GRqxvZV&default-tabs=js,result&host=https://codepen.io

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [October 30, 2020, 8:33pm UTC](https://discourse.threejs.org/t/three-js-screen-width/20302/2 "2020-10-30T20:33:41Z")

</div>

[Functions to calculate the visible width / height at a given z-depth from a perspective camera](https://discourse.threejs.org/t/functions-to-calculate-the-visible-width-height-at-a-given-z-depth-from-a-perspective-camera/269) may help you.

---

<div class="post-metadata">

**Author:** ![Lighty](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lighty/32/43283_2.png) [@Lighty](https://discourse.threejs.org/u/Lighty)\
**Post date:** [October 31, 2020, 8:33am UTC](https://discourse.threejs.org/t/three-js-screen-width/20302/3 "2020-10-31T08:33:01Z")

</div>

yes, thanks.  
I attach the answer.  
https://codepen.io/Lighty/embed/preview/yLJKRZw?height=300&slug-hash=yLJKRZw&default-tabs=js,result&host=https://codepen.io
