Using canvas elements to position divs in three.js

I am currently in the process of developing a custom animation player using Three.js for rendering objects, which is functioning perfectly. However, I am encountering difficulty when trying to incorporate control options at the bottom of the player (such as play, pause, etc). It seems that the canvas is being rendered as the last part of the page. Below is the code snippet:

<body>  
    <div id="playerContainer">
        <div id="renderContainer" style="width:400px;height:300px"></div>
        <div id="controlContainer" style="width:400px;height:30px">
            <input id="rangeBar" type="range" min="0" max="100" value="0" step="1" style="width:400px;height:30px"/>
        </div>      
    </div>      
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://threejs.org/build/three.js"></script>
    <script src="jquery.fullscreen-min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/5/Tween.js"></script>
    <script>    
        container = document.getElementById( 'renderContainer' );
        bar = document.getElementById( 'rangeBar' );
        document.body.appendChild( container ); 
        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(75, $('#renderContainer').width()/$('#renderContainer').height(), 0.1, 1000);
        camera.position.z = 5;
        camera.position.y = 0;
        camera.position.x = 0;
        renderer = new THREE.WebGLRenderer();
        renderer.setSize( $('#renderContainer').width(), $('#renderContainer').height()-30 );
        container.appendChild( renderer.domElement );
        var loader = new THREE.ObjectLoader();
        loader.load("model(1).json", function ( obj ) {
            scene.add( obj );
            render();
            },
            function ( xhr ) {
                console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
            },
            function ( xhr ) {
                console.error( 'An error occurred' );
            }
        );
        var render = function () {
            requestAnimationFrame(render);
            renderer.render(scene, camera);
            TWEEN.update();
        };
        render();
    </script>
</body>

The current result can be previewed here: enter image description here

To address this issue, I have experimented with CSS positions (relative and absolute) as follows:

<div id="playerContainer" style="position: relative;">
    <div id="renderContainer" style="width:400px;height:300px"></div>
    <div id="controlContainer" style="width:400px;height:30px">
        <input id="rangeBar" type="range" min="0" max="100" value="0" step="1" style="position: absolute;top:400px;width:400px;height:30px"/>
    </div>      
</div>  

However, this second approach proved to be less effective. In both scenarios, the playerContainer only contains the controlContainer, and setting any height for the element results in the canvas remaining at the bottom. How can I achieve the desired hierarchy as shown below?

<PLAYER>
  <CANVAS/>
  <CONTROL/>
</PLAYER>

Answer №1

Consider using the following CSS code:

#navigation {
  position: fixed;
  top: 0;
}

Since the navigation element is set to have a fixed position, and there are no other relative elements nearby, it should stay at the top of the viewport.

In addition,

It's not necessary to use position: absolute for the menuBar when its container is already positioned absolutely.

I hope this information proves helpful.

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

Translating from a higher-level programming language to a lower-level programming language

Is compilation effectively the transformation of high-level programming languages (HLL) into machine code or low-level language? If so, why is TypeScript (a HLL) compiled to JavaScript (also a HLL) instead of being compiled to a low-level language? ...

Experiencing problems with malfunctioning javascript tabs

As a beginner user and coder, I'm currently working on creating a portfolio website. I had the idea to implement tabs that would allow for content swapping, but unfortunately, I'm having trouble getting the JavaScript to function correctly. I at ...

Textbox value disappears after being updated

When I click on the edit link (name), the value from the database is displayed as a textbox. However, when I update another normal textbox (age), the value in the edit link textbox disappears. Strangely, if I input a new value into the edit link textbox, i ...

Discovering if the array data is already present in Angular can be accomplished by using specific methods

Here is the snippet of code: data = [ { 'id': 'asdjxv', 'username': 'emma', }, { 'id': 'asqweja', 'username': 'adam', }, { ...

store JSON data within an HTML list element

I've been working on a JavaScript script that allows me to generate list items in HTML. Right now, I have functionality to drag and remove the items using another script. However, I am interested in adding some additional information to each list item ...

The height of the Material UI dropdown is displaying in an improper manner

I'm currently experimenting with the Material UI dropdown on my website, utilizing the react-select library. However, I've encountered an issue where the UI gets compromised when using an option that exceeds the width of the dropdown. If anybody ...

Obtaining the value of an item in an unordered list

Hi everyone, I have been trying to extract the value of <li> elements that display images horizontally. Below is the HTML code I am working with: <div id="layoutInnerOptions"> <ul id="navigationItemsContainer" class="layouts_list"> <l ...

The error callback encountered {"readyState":4,"status":200,"statusText":"success"} while processing

When I make a call to this url, the response is a JSON object when done directly in the browser. However, when I try to do it via ajax using the following code snippet: $.ajax({ url: url, type: "GET", dataType:"jsonp", succ ...

Working with Javascript objects and arrays

Need assistance with manipulating/updating a JavaScript array. Hoping for some help. The initial array looks like this: array('saved_designs'=array()); In Javascript JSON format: {"saved_design":{}} I plan on adding a label and its associa ...

Issue with Image Quality in Woocommerce/Wordpress Products

I'm experiencing an issue with either Wordpress or Woocommerce. Yesterday, I updated Woocommerce while installing a new theme. Unfortunately, I'm facing a problem now where I can't seem to improve the image quality on the product page. Jus ...

Encountering a Meteor issue during the installation of npm packages

When attempting to install cheerio through npm, I encountered a specific error message. Error: Can't set DOCTYPE here. (Meteor sets <!DOCTYPE html> for you) - line 1, file Similarly, when trying to use jsdom, I faced a parse error. Currently ...

Error encountered in Ubuntu while attempting to run a Python script within a Node.js/Express application: spawn EACCES

Recently, I set up a node.js server to run a python script using the python-shell . However, after migrating from Windows to Ubuntu, an EACCES error has been persistently popping up. Despite my attempts to adjust permissions and troubleshoot, I haven' ...

Ways to Personalize Navbar in the Bulma Framework

How can I make the <router link> element in my navbar component full width? I'm also looking for keywords related to achieving this layout. Here is an image of the issue: https://i.sstatic.net/2f2b0BcM.png I want a layout that spans the full ...

Aligning cards

Struggling to align these cards perfectly at center: Despite thorough research on both Google and Stack Overflow, the solution continues to elude me. I've experimented with various methods such as display: flex, justify-content: center, and align-ite ...

Do I need to include success as a parameter in my Ajax call even if my function does not return any values?

When an image is clicked, I trigger an ajax call. The image includes an href tag that opens a different page in a new tab upon click. The purpose of this ajax call is to record the user's clicks on the image for telemetry purposes in a database table. ...

Unable to retrieve Angular Service variable from Controller

I am facing an issue with my Angular Service. I have set up two controllers and one service. The first controller fetches data through an AJAX call and stores it in the service. Then, the second controller tries to access this data from the service. While ...

Fixing a scrolling element within a div located below the screen is my goal, ensuring it remains fixed in place as the user scrolls

I'm facing a challenge that I need help with: My HTML/CSS layout currently looks like this: Screenshot of how my CSS/HTML appears on the screen upon page load: As I scroll down, I encounter a green element: While scrolling down -> Upon further s ...

Exploring Rails 6: Enhancing Web Design with CSS Image Display

I've been attempting to update my webpage background with an image through CSS, but I'm struggling to reference one of my Rails 6 images in the process. Despite trying options like asset-url and image-url, I haven't been successful. However, ...

The local authentication feature in NodeJS Passport is experiencing issues and not functioning properly

I have integrated passportjs local for authentication. However, I am facing an issue where it always redirects to the failureRedirect without displaying any error messages. The redirect also includes the original username and password, resulting in a dupli ...

What is the best approach to create a dynamic value from axios response in a reactive object?

I am attempting to retrieve data from the backend (specifically the user role) and store it in a reactive container with Vue: import {reactive} from "vue"; import axios from "axios"; export const store = reactive({ auth: axios.get ...