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

jQuery problem causes page to scroll when button is clicked

Is there a way to smoothly scroll to the second section of the page when a button is clicked using jQuery? $('.home_scroll_btn a').on('click', function(){ var scrollPosition = $('#intro-home').offset().top; $( ...

Which is quicker when utilizing jQuery selectors: selecting by .classname or div.classname?

Which is quicker: using $(".classname"). or adding the tag to search for as well? $("div.classname") In my opinion, using just the classname would be faster because jQuery can simply loop through all classnames directly, whereas in the second example i ...

Guide to dynamically assigning the id attribute of an HTML element using angularjs (1.x)

Given an HTML element that is a div, what is the method to assign a value to its id attribute? The value should be a combination of a scope variable and a string. ...

Javascript problem with closing the browser window in Selenium WebDriver

Here are a couple of inquiries: Firstly: Is there a method to initiate the browser on a specific URL (instead of about:blank) while also setting the history length to 0 when starting on that URL? Secondly: I suspect this question is related to the one me ...

Using AJAX in JavaScript within an HTML document is a valuable skill to have

I have the following JavaScript function that I need to call the /print2 function without clicking any buttons. I attempted to use Ajax for this, but I am new to Ajax and JavaScript. Can you help me identify where the issue might be? Thank you... <scr ...

Tips for saving the visibility status of a <div> in your browser bookmarks?

Currently, I am in the process of developing a single webpage (index.html). The navigation bar at the top includes links to hash references (DIV IDs). If JavaScript is enabled, clicking on these links triggers a JavaScript function with the onclick attribu ...

Retrieve a file from a remote server without storing it locally on the server

I need to download a zip file from another server without saving it locally. Currently, I am sending a POST request to the server which responds with the zip file, then I save it on my local server and send it using res.download. What I would like is to di ...

Tips for fading out two elements after completing a drag and drop action

Visit this Codepen for more examples - Codepen I have been developing a drag and drop feature in my application. Once the item is dropped, it transitions from red to green and fades out smoothly. The droppable element behind the draggable should also fad ...

Tips for transferring the ngRepeat "template" to an ngDirective with transclude functionality

Example: http://plnkr.co/edit/TiH96FCgOGnXV0suFyJA?p=preview In my ng-directive named myDirective, I have a list of li tags generated using ng-repeat within the directive template. My goal is to define the content of the li tag as part of the myDirective ...

Conflict between jQuery and dynamically changing page content

I've come across multiple discussions on SO regarding similar topics, but I haven't been able to successfully troubleshoot my code to achieve the desired functionality. I'm currently working on an application that involves dynamically chang ...

Encountering a CSS problem while attempting to design a section featuring a background image

On this page, I have the login bar on the right and the footer at the bottom. I want a div to sit in the area currently occupied by the background image and fill it with the full background image. Currently, everything is wrapped in a wrapper and the back ...

What are some effective methods for locating dual edges within a Half-Edge (DCEL) data structure?

I have implemented a HalfEdge data structure to represent the connectivity between faces in my mesh. While importing an external model, I construct the HalfEdge structure. However, for meshes with numerous triangles, the construction process is time-consu ...

When a container is styled with 'overflow-y: auto', it will display additional horizontal and vertical scrolling bars

I have two files, one HTML and one CSS. The HTML file contains the following code: <div class="app"> <div class="header"></div> <div class="main"> <div class="container_1"> ...

What could be causing the tabs to disappear from the Material UI tab component in my React project?

What am I currently working on? I am in the process of developing a horizontally scrollable tab component to select dates within a month For this project, I have decided to utilize the Material UI library Issues Encountered The dates before the 14th Sun ...

What causes errors in jQuery ajax jsonp requests?

"fnServerData": function( sUrl, aoData, fnCallback, oSettings ) { oSettings.jqXHR = $.ajax( { "url": sUrl, "data": aoData, "success": fnCallback, "error":function(msg){ ...

Suggestions for breaking out of the function update()?

Having some trouble escaping my update() function. Here's the attempt I've made: if (score.l1 > 20) { break; } However, all I get is an error message saying "Illegal break statement" ...

The custom tab component in React is currently not accepting the "disabledTabs" prop

I have designed a tab component as shown below: tab/index.jsx import React from 'react'; import TabHeader from './header'; import TabBody from './body'; import TabHeaderList from './header/list'; import TabBodyList ...

Modify the hue of the div as soon as a button on a separate webpage is

Looking for assistance with a page called "diagnosticoST" that contains four buttons (btn-institucional, btn-economico, btn-social, btn-natural). These buttons have different background colors until the survey inside them is completed. Once the user comple ...

Mastering the art of utilizing class attributes and functions from within modules

Currently, I am developing classes in ES6 modules using object literals and my intention is to update object attributes within a function. Although modules run in strict mode by default which ensures safe usage of this, I am uncertain whether calling the ...

EJS Templates with Node.js: Embracing Dynamic Design

Is there a way to dynamically include templates in EJS without knowing the exact file name until runtime? The current EJS includes only allow for specifying the exact template name. Scenario: I have an article layout and the actual article content is stor ...