I’m trying to create a 360 image background that automatically rotates which it is doing and I also prevented the user from having any camera controls but the one thing I can’t figure out is how to prevent the user from having any interaction with whatsoever. The only thing I can’t seem to stop is that whenever the user clicks on the background image that’s spinning the picture pauses for about 3 seconds and then starts spinning again, I’m not sure if there’s a function or way to stop this.
const panoramaImage = new PANOLENS.ImagePanorama("img/ship.jpeg");
const imageContainer = document.querySelector(".image-container");
const viewer = new PANOLENS.Viewer({
container: imageContainer,
autoRotate: true,
autoRotateSpeed: 0.3,
controlBar: false
});
viewer.OrbitControls.noRotate = true;
viewer.OrbitControls.noZoom = true;
viewer.OrbitControls.noPan = true;
viewer.add(panoramaImage);
viewer.onWindowResize();
This is my js code.
2
Answers
If you check the documentation
PANOLENS.Viewer
You can see that there is a
Viewer.disableAutoRate()
to disable auto rotation.Also a
Viewer.enableAutoRate()
to enable it.From there you can implement a function that disable it and with a
setTimeout
that enable it again.Controls are defined with an
THREE.OrbitControls
if you check the source code.Meaning that if for example you want to disable pan interaction you can toggle pan with
OrbitControls.enablePan()
.To prevent your panolens.js image from pausing its spinning motion when the user clicks on it, you can add a click event listener to the infospot. When the user clicks on the infospot, you can display a box or perform any other action you desire. Here’s how you can achieve this:
First, make sure you have included the necessary libraries in your HTML file:
In your JavaScript code (
script.js
), create an infospot and add a click event listener to it:Customize the
infospot.addEventListener
function to perform the desired action when the infospot is clicked. In the example above, a white box is created and appended to the body when the infospot is clicked.Let me know if it worked