this could be a duplicate, but I have not found anything as yet. I am trying to create tooltip for on mouse hover. (perspective camera)
Tooltip issue: https://jsfiddle.net/thehui87/d12fLr0b/14/
threejs r76
function onDocumentMouseMove( event )
{
// update sprite position
// sprite1.position.set( event.clientX, event.clientY, 1 );
// update the mouse variable
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
var vector = new THREE.Vector3( mouse.x, mouse.y, 0 );
vector.unproject(camera);
var dir = vector.sub( camera.position ).normalize();
var distance = - camera.position.z / dir.z;
var pos = camera.position.clone().add( dir.multiplyScalar( distance ) );
sprite1.position.copy(pos);
}
But once i orbit the camera the tooltip moves away.
References for tooltip.
If anyone could kindly point me to the right answer on stackoverflow or provide an alternate solution.
Thanks
Replace:
by:
Well working tooltip is not only correctly placed text label. It has some of show and hide intelligence.
It should:
All of that is included in my solution: http://jsfiddle.net/mmalex/ycnh0wze/
<div id="tooltip"></div>
must be initially added to HTML. The recommended CSS you find below. Crucial to have itposition: fixed;
, anything else is a matter of taste.