Embed a three.js scene into a grid layout using Bootstrap

Trying to embed a three.js scene with toggle switches inside a Bootstrap grid. The issue is that my canvas, which is inside a column, doesn't align properly with the text column on the same row. Any assistance would be greatly appreciated.

Preview: View Preview

HTML:

<section id="intro">
          <div class="container-fluid">
              <div class="row">
                  <div class="col-lg-4 col-md-4 textContainer ">
                    <p>Lorem Ipsum passage variations are available, but most have suffered alteration in some form, injected humor or random words that don't appear believable.
If you're using Lorem Ipsum, ensure there's nothing embarrassing hidden within the text. Lorem Ipsum generators online tend to repeat predefined chunks, making this the first genuine generator on the web.
It utilizes over 200 Latin words combined with various sentence structures to generate realistic Lorem Ipsum. It is always free from repetition, injected humor, or unusual words.</p>
                  

                  </div> <!-- col end -->
                  

                  <div class="col-lg-8 col-md-8">
                      <div id="myCanvas"></div>

                        <button id="polychrome"></button>
                        <button id="blue"></button>
                        <button id='PausePlay'>Pause</button>
                      
                  </div> <!-- col end --->
                  
              </div> <!--row end -->
          </div> <!-- container end -->
      </section>

CSS:

html, body {
    direction: rtl;
font-family: 'Heebo', sans-serif;
    -webkit-font-smoothing: antialiased;
margin: 0;
overflow: hidden;
}

.background {
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -99;
    background-color: lightgray;
    background-repeat: no-repeat;
    background-size: cover;
    
}

Javascript:

// JavaScript code goes here

Answer №1

Your current code is missing the step of adding your renderer to the div.
Here is the original snippet:

container = document.getElementById( 'myCanvas' );
document.body.appendChild( container );
// then later..
document.body.appendChild( renderer.domElement );

In your code, you are...
retrieving a reference to myCanvas,
moving the myCanvas div to the end of the body,
and then adding the renderer canvas as the very last element in the body (after the myCanvas div).

To achieve what you probably intend, try this:

// Get the reference to the container div
container = document.getElementById( 'myCanvas' );
// Append the renderer.domElement (a canvas) to the container div.
container.appendChild( renderer.domElement );

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

Is there a way to specifically transmit ComponentArt CallbackEventArgs from a JavaScript function during a callback?

One of the challenges I'm facing involves implementing a callback in my ComponentArt CallBack control using javascript when the dropdown list is changed. I specifically want to pass both the control and the associated ComponentArt.Web.UI.CallBackEvent ...

Is it possible to dynamically add custom shaders to objects in three.js?

Is it possible to dynamically apply custom shaders to a MeshBasicMaterial with VideoTexture in Three.js? I have successfully applied shaders to the entire scene using THREE.EffectComposer, but how can I apply custom filters to a specific element within the ...

Convert Ajax null value to NoneType in web2py

Every time I save information on a page, an AJAX request is sent with all the necessary data to be stored in the database. The format of this data looks similar to this example: {type: "cover", title: "test", description: null, tags: null} However, when ...

The page switch with a jittery effect

Could really use some assistance with this code that has been giving me trouble for quite a while now. It's a simple HTML, CSS, and JS code involving two pages. [The second page overlaps the first by default, but adjusting the z-index of the first p ...

Is there a way to modify this within a constructor once the item has been chosen from a randomly generated array?

If I use the following code: card01.state = 3; console.log(card01); I can modify the state, but I'm interested in updating the state of the card chosen by the random function. class Item { constructor(name, state) { this.name = name; thi ...

Use a JSON file to dynamically define the file path for static assets in the index.html file of a React application

I am working on a solution to dynamically modify the file paths of static files (js & css) in the index.html file within my create-react-app. My goal is to have these paths directed to different sub-directories based on settings specified in a settings.jso ...

A guide on verifying a phone number using just one character

I am looking to validate a phone number with only one character being allowed. For example, the format should be XXX-XXXXXXX where "-" is the only allowed character. Below is my validation function: function validatePhoneNumber() { if(addform.staff_m ...

Unable to activate focus() on a specific text field

It's quite peculiar. I'm working with a Sammy.js application, and my goal is to set the focus on a text field as soon as the HTML loads. Here's the CoffeeScript code snippet I've written: this.partial('templates/my-template.jqt&ap ...

Once the hidden DIV is revealed, the Youtube video within it begins to load

I currently have a hidden DIV on my website that contains a YouTube clip. My goal is to load the video in the background once the page has fully loaded, so that it's ready to play when the user clicks the button to reveal the DIV. However, at the mo ...

Personalized y axis implementation with Chart.js

I'm working on customizing a bar chart and need to update the "y" axis labels to display Half and Full. The bars in the chart will go all the way up for Full and one halfway for Half. I've looked into using a custom scale, but haven't been a ...

How can I detect Mongoose events through syntax?

Is there a way to detect the open event in Mongoose based on their documentation located here? According to the documentation, once connected, the open event is fired on the Connection instance. If you're using mongoose.connect, the Connection is m ...

Using Node.js to send a photo through a Telegram Bot

I've been trying to send a photo via node.js using this function, but it's not working. telegram-bot-api https://www.npmjs.com/package/telegram-bot-api var telegram = require('telegram-bot-api'); var api = new telegram({ token: & ...

Leverage npm JavaScript packages within an Ionic2 TypeScript project

Just diving into my first project with Ionic2 (TypeScript) and I'm trying to incorporate the npm JavaScript package. Specifically, I am utilizing https://github.com/huttarichard/instagram-private-api I'm a bit confused on how to correctly use im ...

Toggle a MutationObserver using a button to stop and start monitoring for changes

Is there a way to connect a MutationObserver and disconnect it using the same button? I know how to do each separately, but I want to use just one button. How can I achieve this? Apologies for my poor English. var target = document.getElementsByClassNa ...

The updated positions of vertices in three.js geometry after they have been moved

I am new to 3D manipulation and learning about Three.js. One thing I'm struggling with is understanding how to retrieve the updated vertex coordinates after moving a geometry. The code I've written below seems to only return the original coordina ...

I possess a collection of objects, where each object is composed of maximum and minimum key-value pairs. What is the method to determine which object includes a specified value within it?

I have a list of insurance rates structured like this const insuranceRate = [ { "min_value": 1, "max_value": 25000, "add": 328 }, { "min_value": 25001, "max_value": 25500, "add& ...

Voice crashes in Discord.js after the audio has been playing for a short while

Every time I try to play a song, the bot crashes and gives an "aborted" error message after about a minute. music = { "resource": createAudioResource(ytdl(parameters[0], {filter: "audioonly"}), {inputType: StreamType.Arbit ...

Storing input field values in JavaScript using the onchange event handler.Would you like a different revision

I am looking to calculate the area by multiplying width and height entered into input fields, and then display the result. Any guidance would be greatly appreciated. Thank you! Here is my current code. const width = document.querySelector("#width"); con ...

Validate in React whether a key pair exists in the state based on a given parameter

I'm grappling with the challenge of optimizing my application by consolidating multiple dialog window functions into a single function. Currently, I have separate functions for each dialog window that toggle their state: toggleSettingsDialogue = () = ...

Using JavaScript, is there a way to modify a JSON parameter within an API?

My API provides JSON data structured like this: [{"NAME":"john","SURNAME":"johny","ADULT":"3","CHILD":"3","BABY":"0",}] In my JavaScript function, I need to send a request to a web service that will update the value of "BABY" from "0" to "1". Can this be ...