How To Make A Clickable Css3dobject
I'm using THREE JS CSS3DRenderer - trying to make a CSS3DObject update it's position.z on click. Here's my code: var element = document.createElement( 'div' ); element.style.width
Solution 1:
Here is one way to handle a click event from a CSS3DObject, and get access to the element's parent object:
varobject = new THREE.CSS3DObject( element );
element.parent = object;
object.element.onclick = function() { this.parent.position.y += 10; };
three.js r.65
Solution 2:
Have you try with mousedown and mouseup event? See my sample:
var mouseDown = false,
mouseX = 0,
mouseY = 0;
functiononMouseDown(evt) {
evt.preventDefault();
mouseDown = true;
mouseX = evt.clientX;
mouseY = evt.clientY;
}
functiononMouseUp(evt) {
evt.preventDefault();
mouseDown = false;
}
functionaddMouseHandler(canvas) {
canvas.addEventListener('mousedown', onMouseDown, false);
canvas.addEventListener('mouseup', onMouseUp, false);
}
$(document).ready(function () {
var canvas= document.getElementById("canvas");
addMouseHandler(canvas);
});
Post a Comment for "How To Make A Clickable Css3dobject"