jeromeetienne/threex — Issue #15: DomEvent  _onMouseEvent/_onMouseMove  error when Scroll
Author: bloublou
Created: 2012-02-06 19:28:44+00:00
State: open

Hello,

First thanks for your lib.

About the issue :
When no scroll is set no problem, all works fine and mouse event fired on correct object.
But when canvas container is on a page, and page is scrolling a bug appears : Mouse position does not calculate correctly and a bad or no object is selected :

original code : OK in case domElement == window
var mouseX	= +(domEvent.clientX / window.innerWidth ) * 2 - 1;
var mouseY	= -(domEvent.clientY / window.innerHeight) * 2 + 1;

but KO if domElement != window
one possible solution for _onMouseEvent/_onMouseMove :

var mouseX = +((domEvent.clientX - this.domElement.offset().left - $(window).scrollLeft()) / this.domElement.width()) * 2 - 1;
var mouseY = -((domEvent.clientY - this.domElement.offset().top - $(window).scrollTop()) / this.domElement.height()) * 2 + 1;

Now ScrollLeft/Top are taken into consideration with domElement position.

PoP