Raycaster not working in wordpressr

Raycaster not working in wordpress but same code is working on my machine, Can anyone tell me what i did wrong? below is my code -

document.addEventListener('mousemove', onMouse);

function onMouse(event) {
			mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
			mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
			mouse.z = 0;
			raycaster.setFromCamera(mouse, camera);
			isects = raycaster.intersectObjects(alvos, false);
			if (isects.length > 0) {
				document.documentElement.style.cursor = 'pointer';
				document.body.style.cursor = 'pointer';
			} else {
				document.documentElement.style.cursor = 'default';
				document.body.style.cursor = 'default';
			}
			if (isects.length > 0) {
				isected = isects[0].object;
			} else {
				isected = null;
			}
		}

The code above is for full-window/full-tab mode. If your canvas in Wordpress is taking only a part of the window, the raycasting will almost always miss its target.

1 Like

should fix the issue, maybe play with the ‘+’ or ‘-’. The canvas might be in various position relative to the mouse position. It works on your machine because the canvas is in fixed position but in word press it might be different position