Issue with responsive canvas height in Particle-JS

Recently, I've been working on a Bootstrap portfolio where I am experimenting with implementing particle.js over a profile picture.

I placed the particles inside a DIV and set a background image as the profile photo. The issue arises when I reload the screen; on XL screens and resizing from xl > lg > md it works fine. However, when the screen size increases from md to lg to xl, the canvas height does not adjust according to its parent container. Can anyone help me figure this out?

You can view the portfolio project at the following link:

Click here to view the project

The problem with Canvas Height is illustrated in this image:

https://i.sstatic.net/QWNP2.png

<header id="main-header">
    <!-- full row for image to the left and others to the right -->
    <div class="row no-gutters">
      <!-- images to the left with 4 col -->
      <div class=" col-md-5 col-lg-4">

       <!-- PARTICLE JS WITH PROFILE PICTURE -->

        <div id="particles-js"></div>

      </div>

      <!-- Name and Menu to the right with 8 col -->
      <div class=" col-md-7 col-lg-8">

      </div>
    </div>
  </header>
#particles-js {
    width: 100%;
    height: 100%;
    background-color: #b61924;
    background-image: url('../img/profile.jpg');
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: no-repeat;
}

Answer №1

To perfectly center the particle div, set max-width, max-height, and margin: 0 auto properties on the #particles-js id.

#particles-js {
  max-width: 380px;
  max-height: 401px;
  margin: 0 auto;
}

Answer №2

Let me share what really made a difference for me

// This is the code snippet I used to create a particles animation on my website
var particleAnimationContainer = document.querySelector('body');

// Set the dimensions of the animation container to match the screen size
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;

particleAnimationContainer.width(screenWidth);
particleAnimationContainer.height(screenHeight);

// Start the particles animation using the provided particles configuration from particles.json      
particlesJS("id-of-body", particlesConfig);

Answer №3

To easily set the size of particles js canvas to a custom height or width, create a wrapper div and specify the particle.js options with the 'style' attribute

Set the position attribute to "absolute" for the wrapper div
Then set the position attribute to "relative" and define your desired height and width

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

Using JavaScript to pass a newly created variable as an argument in a default

Currently, I am developing a node application that heavily utilizes promises. To enhance the readability of my code, I have been removing anonymous functions and storing them in a JavaScript object called "myCallbacks". Here's an example: let myCallb ...

The alignment of flex items is not consistent in Webkit browsers

One of the issues I am facing involves a text field that contains a cogwheel symbol which opens a popup menu with different search options. The layout is set up using a flexible box model for certain elements. After testing in Firefox, the display is as e ...

Having trouble retrieving the animation keyframe names from the SCSS file in animate.css

I'm currently experimenting with incorporating animate.css into my React/Next.js project. While I can easily create animations using animate.css's inline class names, I'm facing challenges in calling animate.css's keyframe animations fr ...

Restrict the height of a division based on the adjacent division

Within the parent div, I have two child div elements that are meant to be positioned side by side. The first element contains an image which loads dynamically, meaning its height is unknown in advance. I want the parent div's total height to match the ...

Tips for sending a JSON array from a controller to JavaScript using AJAX in a view file

I've been struggling to send an array of Document objects from a method (let's say it's in a controller) to the JavaScript function where the method is being called (in a view). Oddly enough, the method refuses to pass the array - it only wo ...

Ways to customize the bootstrap-datetimepicker to display time in 15-minute increments

Here is my code in JavaScript to increment by minutes at a 1-hour interval: fillMinutes = function () { var table = widget.find('.timepicker-minutes table'), currentMinute = viewDate.clone().startOf('h'), ...

Guidelines on how to retrieve information from an AJAX request in PHP

I am in the process of developing an application that involves calling a JS function in PHP like this: $data = "<script>JSFunction();</script>"; The JSFunction is defined as follows: function JSFunction(){ $.ajax({ type: 'POST' ...

Is it feasible to create a comprehensive CRUD application without utilizing a database?

As I utilize a JSON file from my GitHub repository as a mock backend, I have mastered fetching and reading all the information. Is there a way to modify or add new data to this JSON file? Could opting for an alternate mock backend such as Mocky.io provid ...

"Is there a way to alter the background color of the second span within a Bootstrap row

I currently have 4 WordPress services in a loop, and I am trying to change the background color of the second service. However, when I try to apply the CSS background property, it ends up affecting all of the services. Here is my template code: <div ...

How to use PHP DOM to selectively remove HTML tags while preserving inner tags and text content

Looking for a way to remove specific tags in an HTML document while preserving inner tags and text? I initially tried using Simple HTML Dom Parser, but found it to be inefficient with large files. I've heard that native PHP tools like DOMDocument are ...

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

Adjust the X and Y coordinates when hovering over an element in d3.js

I have implemented a mouseover function to display the x and y coordinates on my line graph. However, I am in need of assistance in rewriting the tooltip function so that it accurately shows the x and y coordinate position during the mouseover event. Any h ...

Convert JSON information for use in ChartJS

I've been delving into the world of ChartJs and have encountered a bit of a roadblock. I'm looking to decipher how to convert JSON data into labels and data for a bar chart. The JSON data consists of an array of product orders. With varying numb ...

What is the best way to ensure that table cells containing images resize without any issues?

I need help with centering and resizing an image on a screen. The image is divided into small images within cells, but I can't seem to get it right. Despite trying various solutions and spending hours resizing the table and images, the final output a ...

What is the best way to loop through jsoup elements while skipping the initial two results?

Extracting desired data from the following HTML snippet: <div class='col5'> <strong><a href="/stellenangebote/107278-supporter-sap-crm?page=1&amp;query%5Bcity%5D=&amp;query%5Bradius%5D=100&amp;query%5Btext%5D=SOA+SAP" ...

Can React Router be integrated with Material UI tabs?

I have made some changes to the code of the Tabs component in material ui, <AppBar position="static"> <Tabs variant="fullWidth" value={value} onChange={handleChange} aria-label="nav tabs example" > < ...

`Change the output path and utilize URL helpers for CSS in Compass`

Currently facing an issue with altering the .css output path to a specific file in a compass project. Imagine having a directory structure like this: / ..Fonts ..Folder ..Images ..Sass .._mixins.scss ..[other_stuff] ..Styles ..config.rb Her ...

Preventing the collapse of the right column in a 2-column layout with Bootstrap 3

I've recently begun exploring Bootstrap and am attempting to achieve the following: (Left column - larger) Heading Heading 2 Heading Image Heading Image Heading Address (Right column - smaller) Heading Paragraph List items My issue ...

Is there a way to swap out the audio tracks for a .mp4 video file on the web?

I am currently working with a video file in .mp4 format that has multiple audio tracks embedded within it. Despite using VideoJS & ReactPlayer, I have been unable to detect these audio tracks. Is there a method to specifically target a particular audio tr ...

Need to import a custom module using npm and TypeScript

Exploring two projects: main-project and lib-project, both written in TypeScript and compiled to common JavaScript using gulp. Our objective is to require lib-project in main-project. lib-project |-- package.json |-- gulpfile.js |-- dist |-- index.js ...