Ways to align div elements

I am currently in the process of developing my own custom animation player. Utilizing Three.js for object rendering has been successful so far. However, the challenge lies in incorporating control options at the bottom of the player interface (such as play and pause buttons). I suspect that the canvas is being rendered as the last element on the page. Here is a snippet of my code:

<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 happened' );
                    }
                );
                var render = function () {
                    requestAnimationFrame(render);
                    renderer.render(scene, camera);
                    TWEEN.update();
                };
                render();
            </script>
    </body>

The output can be viewed here: enter image description here

After researching css positioning techniques like relative and absolute, I attempted to implement it in this manner:

<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>  

Unfortunately, this solution did not produce the desired outcome. In both scenarios, the playerContainer only contains the controlContainer element, causing the canvas to remain at the bottom. How can I achieve the following hierarchy?

<PLAYER>
  <RENDERER/>
  <CONTROL/>
</PLAYER>

@UPDATE I am aiming for a layout similar to this:

https://i.stack.imgur.com/V85hj.png

as illustrated below:

-green - playerContainer
-red - rendererContainer
-yellow - controlContainer

Answer №1

To successfully insert your renderContainer element into the playerContainer after the canvas has been rendered, you will need to utilize JavaScript.

Make sure to add the renderContainer as the first child of the playerContainer by using the insertBefore() method.

Here is the code snippet that accomplishes this:

var playerContainer = document.getElementById("playerContainer");

playerContainer.insertBefore(document.getElementById("renderContainer"), playerContainer.firstChild);

I have prepared a fiddle for demonstration purposes. Feel free to check out the live example here: https://jsfiddle.net/nashcheez/LvjykL23/

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

When using jQuery's POST method, the "done" event is triggered, however, no data is being sent

I've been working on implementing AJAX form submission and wrote a function to handle it when the button is clicked: function putUser() { $('button#putUser').on('click', function() { var user = $('input#user' ...

The call is not being answered by the server route (NodeJS + express)

I have encountered an issue while setting up a server using NodeJS and Express. When I attempt to make a get request to the basic route ('http://localhost:3000/'), the request seems to hang indefinitely. Despite thoroughly reviewing my code multi ...

How can you loop through keys and values in a JSON object using JavaScript?

I am attempting to cycle through the JSON data below: { "VERSION" : "2006-10-27.a", "JOBNAME" : "EXEC_", "JOBHOST" : "Test", "LSFQUEUE" : "45", "LSFLIMIT" : "2006-10-27", "NEWUSER" : "3", "NEWGROUP" : "2", "NEWMODUS" : "640" } The keys in this JSON are d ...

Sending Code Through POST Using jQuery

Users can input code in a textarea with the id of 'code_box'. <textarea id = 'code_box'></textarea> The following jQuery uses ajax to send the code to a PHP script for processing. $('#submit_button').click(funct ...

Learn the technique of initiating one action from within another with Next Redux

I'm looking to set up user authorization logic when the page loads. My initial plan is to first check if the token is stored in the cookies using the function checkUserToken. Depending on whether the token is present or not, I will then call another f ...

Error: The call stack has reached its maximum size while running an npm install

Attempting to execute npm install, encountered the following console output: npm ERR! Linux 4.8.0-27-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" npm ERR! node v6.9.1 npm ERR! npm v3.10.8 npm ERR! Maximum call stack size exceeded npm ...

Attach two divs to the top-right and bottom-left corners using adhesive

Currently, I am utilizing jQuery's resizable() function. My goal is to have one div positioned on the top-right corner and another div on the bottom-left corner at all times. Essentially, I want these two divs to act as if they were the resizable hand ...

WebDriverException: Error: {"errorMessage":"The object is undefined"

I encountered an error while running the code on this HTML page, specifically at /html/body/div[3]/div[1]/div[1]/div[1]/div/div[10]/a/div[1]/div[2]: WebDriverException: Message: {"errorMessage":"null is not an object (near '...ull).singleNodeVa ...

Issues with Javascript functionality on aspdotnetstorefront site

Lately, I've been facing some challenges with my Javascript and jQuery codes when trying to implement them in the storefront. Despite attempting different methods to create a slider, none seem to work within the store environment - even though they fu ...

Cloud function -> time stamps evaluation

I've been working on a cloud function to delete items in the "links" collection that have an end time older than the current timestamp. Although my function runs without any errors, it's not deleting the items as expected and is causing me quite ...

Utilize the grid system from Bootstrap to style HTML div elements

I am working on my angular application and need help with styling items in a Bootstrap grid based on the number of elements in an array. Here's what I'm looking to achieve: If there are 5 items in the array, I want to display the first two items ...

Eliminate repeated entries in a drop-down menu and display them with commas in between

I am working with a list that contains various language combinations: German to English German to Spanish German to Chinese German to French English to Spanish English to French English to Greek English to Portuguese Does anyone have suggestions on how ...

Launching a Node.js command-line interface to NPM, developed using TypeScript

I'm struggling with deploying my Node CLI tool to NPM. During development and testing, everything works fine. I can even use `npm link` on the repo without any issues. After successfully publishing and downloading the package, the application crashes ...

Using jQuery and regex to validate a long string containing lowercase letters, uppercase letters, numbers, special characters, and

Good day, I've been struggling with jquery regex and could really use some assistance. I've been stuck on this since last night and finally decided to seek help :) Here is my regex code along with the string stored in the 'exg' variabl ...

The Material-ui Select component is experiencing issues with updating the state accurately

When creating a multiple select input using Material-UI, I encountered an issue with setting the default selected values from state. Despite having an array of two objects in the state and setting it as the select value, the default objects are not being ...

Discovering relative URLs within an MVC 4 framework

Seeking a solution for storing the fully qualified URL of a relative path in MVC: ~/Content/themes/base/jquery-ui.min.css" In my scenario, I have a hidden input field: <input type="hidden" id="siteUrl" value=""/> I attempted to populate this hidd ...

Angular Delight: Jaw-Dropping Animation

After setting up my first Angular project, I wanted to incorporate Angular Animations to bring life to my content as the user scrolls through the page. I aimed to not only have the content appear on scroll but also implement a staggering animation effect. ...

choose exclusively the text within the elementor navigation menu

I've been tinkering with this issue for a few hours now. I have a vertical Elementor navigation menu and I'd like to add a hover effect to it. So far, I can only select the entire column and apply the effect to that, not just the length of the t ...

Mozilla Firefox does not have the capability to support preloading

I am having an issue with preloading CSS sheets. I attempted to preload the CSS sheet using the preload attribute in HTML. It works fine on Google Chrome, but unfortunately, it does not work on Firefox. <head> <link href=assets/css/master.c ...

Form submission requires a checkbox to be checked

I have been searching for a way to make checkboxes required. Is there a method similar to using required="required"? Currently, I generate my checkboxes in the following manner and would really appreciate any guidance on this topic. It's crucial for m ...