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:
var object = 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;
function onMouseDown(evt) {
evt.preventDefault();
mouseDown = true;
mouseX = evt.clientX;
mouseY = evt.clientY;
}
function onMouseUp(evt) {
evt.preventDefault();
mouseDown = false;
}
function addMouseHandler(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"