Customize GUI - adjusting menu dimensions and placement (javascript / css)

I’ve been experimenting with integrating Dat GUI into my Three.js project for adding some controls. The interface of Dat GUI really appeals to me, but I’m facing challenges in terms of positioning the menu on the page. Specifically, I’m looking to center the menu both horizontally and vertically while also defining a custom width and height. Is it feasible to achieve this?

My current approach involves attempting to center the menu horizontally, which seems to be partially successful. However, the vertical alignment is off (stuck at the top) and the size remains unchanged despite specifying width and height parameters.

If anyone could offer guidance on this matter, I’d greatly appreciate it.

Javascript:

var gui;

var MenuClass = function() 
{
    this.speed = 0.5;
};

var theMenu = new MenuClass();

gui = new dat.GUI();
gui.domElement.id = 'gui_css';

gui.add(theMenu, 'speed', -5, 5);

CSS:

#gui_css 
{    
    position: absolute;

    left: 50%;
    top: 50%;

    width: 400px;
    height: 200px;
}

Answer №1

Consider the following: to include a div as a container for your dat.GUI element

<div id="gui_container"></div>

then, in your code:

var gui = new dat.GUI({ autoPlace: false });
gui.domElement.id = 'gui';
gui_container.appendChild(gui.domElement);

and for styling purposes:

#gui_container{
  position: absolute;
  top: 50%;
  left: 50%;
}
#gui{
  transform:translate(-50%, -75px);
}

Keep in mind that the value of -75px in

transform:translate(-50%, -75px);
indicates that the gui.domElement does not have a defined height, and you are adjusting the y-axis translation to approximately half its height on the screen.

Here is an example on jsfiddle for reference.

Answer №2

give this a shot:

    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;

with these CSS properties, you can center the element both horizontally and vertically as long as it has width and height. Otherwise, it will stretch the element accordingly.

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

Guide to converting a specific tag into div using Javascript

I am working with some HTML code that includes a div: <div class="myDiv"> <a href="" title="">My link</a> <p>This is a paragraph</p> <script>//This is a script</script> </div> Additionally, I ha ...

What is the best way to ensure that my website functions properly on Safari mobile?

I successfully created a website that functions well on my computer across all modern browsers. However, a user reported that it is not working on Safari mobile. Upon testing the website on Safari for Windows, it appeared to display correctly. After view ...

What are the steps to create a "gooey glide" animation using React and MUI?

I am looking to create a unique animation for my list of items on a web page. My goal is to have the items slide in one by one with rapid succession and then slightly shrink once they reach their final position, similar to how pillows might fall or like a ...

What strategies should be considered for styling AngularJS components?

Currently, I am engaged in a project using AngularJS with the intention of gradually organizing things for Angular 6 or whichever version is available when we begin the upgrade process. A significant part of this endeavor involves converting existing direc ...

Issues with unchecking modal icheck box when closing in Bootstrap JavaScript

Here is the HTML code that I am working with: <div class="modal inmodal" id="handleUserModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> &l ...

"Incorporating Social Media Icons into Your Website using HTML and CSS

Looking to recreate a design featuring social media icons (LinkedIn, Facebook, Google Plus, Twitter) using HTML and CSS. https://i.sstatic.net/016im.png Although I have managed to create something similar in fiddle with font-awesome, it's not an exa ...

Achieving enlightenment with Satori in NextJS: Transforming SVG to PNG in a NodeJS Environment

I am currently exploring the capabilities of satori and integrating it into my next.js api routes. (I'm unable to utilize the vercel/og package). While I have successfully set everything up, I'm facing a challenge in converting the svg image gen ...

Transform JSON reply in JavaScript/Typescript/Angular

Looking for assistance with restructuring JSON data received from a server API for easier processing. You can find the input JSON file at assets/input-json.json within the stackblitz project: https://stackblitz.com/edit/angular-ivy-87qser?file=src/assets/ ...

Troubleshooting Shader Extensions in THREE.js

My application functions flawlessly on almost every device I've tested it on, but one of my users is experiencing the following console errors in Google Chrome (works fine in Firefox). The app is only partially loading for this user. THREE.WebGLRende ...

JavaScript Compositions and Incorporations

Currently, I am delving into the world of compositions in Javascript and would like to confirm if my current approach is correct. I have been working on some exercises that follow this structure: class Animal { // constructor() { // } eat ...

Generating a JSON file by combining data from two separate lists in order to render a visually appealing stacked bar chart

Combining two lists to create a JSON for generating a stacked bar chart using JavaScript list1 = ['2019-03-05', '2019-02-20', '2019-02-20', '2019-02-19', '2019-02-18', '2019-02-16', '2019-02 ...

Issue with Tweening in Three.js: Initial value does not change

Having trouble with tweening my camera position. I've set up a Codepen with minimal code to showcase the issue, complete with annotations and plenty of console.log() statements for debugging purposes. Check out the Codepen The starting point of my c ...

Conceal the Jquery Class if there are no classes currently visible

There is a section of text labeled (16 Courses) below that I am trying to hide using JQuery, but so far, all my attempts have failed. Can anyone offer any guidance on how to successfully hide only this particular text? <div id="programAttributes"> ...

Tips on implementing jQuery autocomplete feature using PHP, MySQL, and Ajax then retrieving the data to be passed to

I've successfully implemented a JavaScript code for my autocomplete search feature. However, the data returned by the search is currently hardcoded in the code snippet below. I'm looking to retrieve the data from MySQL using PHP instead. Could a ...

Adjust the text appearance of the graph in ApexCharts

Is there a way to adjust the font size of the donut chart generated by using apexchart? You can view the image here. <template> <section> <v-card raised> <v-card-title class="blue--text">Requests Overview</v-card-ti ...

PHP - Divide an array into smaller segments

I currently have a variable named $recipe['ingredients']; Within this variable, the contents are listed as: 100ml milk, 350ml double cream, 150ml water I am attempting to separate these ingredients into a list format like so: <ul> & ...

Tips for preserving the value retrieved from a $http request when navigating back in the browser

In my application, I have a "search" button that retrieves an array of objects from a REST service. These values are then populated into a table using the ng-repeat directive. When a column is clicked, the page navigates to the next page with more details ...

Shifting Transition for Customer Reviews

I am working on implementing a testimonial slider on my webpage located at . I am trying to make it automatically slide by itself, but have been unsuccessful so far. I would appreciate if you could visit the demo page on my website and help identify what ...

Understanding ReactJS's process of batching all DOM updates within a single event loop, ultimately minimizing the number of repaints needed

While perusing an article on DOM updates in ReactJS, I came across the concept of React updating all changes within a single event loop. Having a background in understanding event loops in JavaScript and how they function in core JavaScript, I am curious ...

Utilize Angular to simultaneously filter search results by URL and make selections in a dropdown menu

As a newcomer to the Angular JS framework, I have successfully created a client-company table where clients can be filtered by company name using a drop-down menu. However, I am now looking to implement a filtering mechanism based on the URL structure su ...