devN
devN

Reputation: 912

How to update z value when scrolled on three.js render?

I am trying to add scroll event listener to my three.js project.

I tried this code but it doesn't work and I don't know why.

window.addEventListener("scroll", function(e) {

    console.log("scrolled")

    // code to increment object.position.z 

}, true);

I tried OrbitControls.js and TrackballControls.js, but it zooms. I don't want the zoom feature.

Any ideas?

Upvotes: 1

Views: 2105

Answers (2)

Kaivosukeltaja
Kaivosukeltaja

Reputation: 15735

The scroll event will only fire if you do actual scrolling by having more content than can fit on the screen. If you have the canvas at 100% width and height the wheel won't send any scroll events. Try the wheel event instead.

window.addEventListener("wheel", function(e) {
  console.log("scrolled")
  // code to increment object.position.z 
}, true);

Upvotes: 2

Weppy
Weppy

Reputation: 395

What if you add your event on your canvas instead of the window element? If you can provide some code that would help also!

Upvotes: 0

Related Questions