Enhance User Interaction by Making HTML Elements Clickable on Top of Three.js Render

I'm currently working on an animation project using Three.js that involves moving objects. In this animation, I've created a text bubble that appears when an object is clicked, along with an "X" button to close it. However, I'm facing an issue where if the X button overlaps with a 3D object, the button gets ignored and the 3D object gets clicked instead. How can I ensure that the HTML content always takes priority over the 3D objects?

Raycasting is being used to detect clicks on the 3D objects. Despite attempting to set a higher z-order for the button, it hasn't resolved the problem. It's important to note that visually, the HTML content is positioned on top of the 3D objects.

Furthermore, it would be ideal if clicking within the text bubble doesn't register as a click on any object beneath it.

Edit: Here's a simplified version of the code I'm using for the onclick function (which works for my 3D objects). I've also separately bound a specific onclick function to the problematic button.

document.addEventListener('mousedown', () => {
    raycaster.setFromCamera(mouse, camera);
    const hits = raycaster.intersectObjects(scene.children);
    if(hits.length > 0) {
        ---do stuff---
    }
    renderer.render(scene, camera);
});

Answer №1

Implementing this in react was simple for me using only the z-index property for the clickable elements. However, if this doesn't yield the desired results, you may want to consider applying pointer-events: none; to your 3D render. You can view a screen capture of this in action here: . The webGL globe is created using three.js within a react environment and spans the entire width of the active area where the links are positioned on top.

The outer container is styled with position: relative;...the links reside within a div that has

position: absolute; z-index: 1000;
, while the three.js earth render is placed as the final div within the same container.

Answer №2

Refer to the top solution in this URL: How do I prevent a THREE.js raycast from hitting HTML elements?

This method worked flawlessly for my situation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying items in the shopping cart across two separate columns

I have a website located at Within that page, I have included the Cart table using a woocommerce shortcode. Currently, the cart table is positioned below the billing details and payment options section. My goal is to move this cart table to be situated ...

The parent is relatively positioned and its child is absolutely positioned and floated to the left

I'm currently working on a design where I have a group of parent containers with the float left property applied. Inside each parent container, there is a child div with position absolute defined within them. Here's an example: <div class="wr ...

Angular and Ionic collaborate by using ngFor to pass on the item.id during a (click) event

I have a list of items and I want to dynamically change the height of a card when I click on a button that is located on the card. Can anyone guide me on how to achieve this? I attempted to pass the item.id through a click event and use the id in a functi ...

How can I access the '[native code]' using getAllResponseHeaders() in JavaScript?

Currently, I am making an AJAX call and trying to access the response headers. This is my code snippet: var xhr = new XMLHttpRequest; xhr.getAllResponseHeaders(); When I check the console, all I see is '[native code]'. Can anyone provide me ...

Enhancing bar border with the addition of a separator

Our current situation is similar to this: https://i.stack.imgur.com/Luj1S.png but our goal is to have a chart with separators on both sides of the age brackets, like this: https://i.stack.imgur.com/03UpO.png In order to achieve this, we have utilized t ...

A guide on implementing Smooth Shading on Collada models in Three.js using the ColladaLoader

Displayed above is a model created with the collada loader example in threejs, showcasing Flat Shading (resulting in the blocky nose). Below is the same model but rendered with a Smooth Shader in meshlab. I have successfully applied smooth shading to an ...

Cannot get Firebase's set() method to work when called within onAuthStateChanged() function

As I embark on developing my first significant web application using ReactJS with Firebase as the backend database, everything was progressing smoothly until a troublesome issue surfaced. The hurdle I encountered involves saving user information upon thei ...

Remove a single item from a dynamically generated ObjectArray

I am working with an object array list that is formatted like this: var myFormData = [ { id: 1, name: "first name", type: "test", root: "/myfolder" }, { id: 3, name: "your name", type: "test 2", root: "/myfolder2" }, { ...

Retrieve the content outside of the quotation marks in an HTML document through web scraping

I need help extracting specific information from a web page using Python. The data I want is not within quotation marks, as shown below: nummber = page_soup.findAll("span", {"id": "referenznummer"}) nummber # result [<span ...

Google Cloud Functions do not allow initialization of functions at runtime

I am encountering an issue while deploying a basic function on Google Cloud Functions. The error message I am receiving states: Function cannot be initialized. Error: function terminated. Recommended action: inspect logs for termination reason. Here is th ...

What are some strategies to stop a jQuery UI button created with a link from inheriting the link's text color?

I recently came across a recommendation to create a jQuery button on top of a link for redirect purposes: <a href="/search" class="button">My link</> $(".button").button(); However, I noticed that if the button class has a red foreground colo ...

Encountering a 400 error while attempting to append a comma-separated string to the end of an API call

When making this API call, a comma-separated list must be included at the end of the URL. Initially, I entered the data like this at the end of the URL: const matchDetails = await axios.get(`http://api.paladins.com/paladinsapi.svc/getmatchdetailsbatchJso ...

"Creating a new object in ThreeJs by deriving from an existing object

After importing an .obj file, I successfully created an object that I now want to clone and assign unique coordinates to. Specifically, I have a wall to which I have attached another object (a window) as a child. Everything functions correctly when movin ...

React Native: Avoiding Infinite Loops in useEffect

I am facing an issue where my app goes into an infinite loop because pointsData is inside the useEffect function. How can I resolve this situation? function useGetPoints() { const [pointsData, setPointsData] = useState<PointTbleType[]>([]); ...

The background image in CSS fails to display when a relative path is utilized

Currently, I am working on a JavaFX project which has the following file structure (CEP serves as the root directory): CEP +img menu.jpg +src +css_files MainMenu.css The main objective is to set the background image from the img dir ...

Determining the exact position of an image with resizeMode set to 'contain' in React Native

I am currently developing an object detection app using React Native. The process involves sending an image to the Google Vision API, which then returns a JSON file containing coordinates and sizes of objects detected within the image. My goal is to draw r ...

Creating a three-dimensional representation by projecting onto the surface of a sphere in ThreeJS

3D animation is a realm filled with numerous terms and concepts that are unfamiliar to me. I am particularly confused about the significance of "UV" in 3D rendering and the tools used for mapping pixels onto a mesh. I have an image captured by a 360-degre ...

How does Firefox still autocomplete even with a different input label?

How does Firefox decide where to autofill passwords and usernames? I've noticed that even after changing the name, id, title, or class of an input element, Firefox still automatically fills it with my password or email address. ...

The backend post request is returning only "undefined" in JavaScript

Hey there, I'm still learning JS so please bear with me. I've been working on incrementing a value in a JSON file within my JS backend app. However, whenever I try to increase the associated value by the key, it ends up creating a new section la ...

Generate HTML on the fly using Node variables

Utilizing Node.js with Express as the server, I have implemented a feature where users can upload .CSV files containing data. This data is then parsed and stored in a main array made up of arrays, with each line representing one array element. Currently, I ...