Expand the Canvas element to match the size of the div below

I am working with a canvas that I want to span 100% of the screen width and at least 100% of the screen height, with the ability to extend further if the next div exceeds the bottom of the screen.

To populate the canvas, I am using Trianglify.

`

` `
`
    var pattern = Trianglify({
      cell_size: 25,
      x_colors: 'Greens'
    });
    pattern.canvas(document.getElementById('container1'));
    setInterval(function() {
      // method to be executed;
      var pattern = Trianglify({
        cell_size: 25,
        x_colors: 'Greens'
      });
      pattern.canvas(document.getElementById('container1'));
    }, 1000);
canvas#container1 {
  position: absolute;
  width: 100vw;
  min-height: 100vh;
}
.screen-container {
  min-height: 100vh;
  position: relative
}
.trianglify-container {
  background-color: transparent;
  color: #fff;
  text-align: center;
  padding-top: 20vh;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/1.0.1/trianglify.min.js"></script>
<canvas id="container1"></canvas>
<div class="screen-container trianglify-container">
  <div class="container">
    ...
  </div>
</div>

UPDATE

The main requirement is for the div immediately following the canvas to have the canvas as its background, spanning at least one full screen. If there is an alternative approach to achieve this, I am open to adapting my current method.

Answer №1

Are you satisfied with this outcome?

-- Lengthy information --

var pattern = Trianglify({
      cell_size: 25,
      x_colors: 'Greens'
    });
    pattern.canvas(document.getElementById('container1'));
    setInterval(function() {
      // method to be executed;
      var pattern = Trianglify({
        cell_size: 25,
        x_colors: 'Greens'
      });
      pattern.canvas(document.getElementById('container1'));
    }, 1000);
.outer-wrapper{
  min-height: 100vh;
  position: relative;
}
canvas#container1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.screen-container {
  /*min-height: 100vh;*/
  position: relative;
}
.trianglify-container {
  background-color: transparent;
  color: #fff;
  text-align: center;
  /*padding-top: 20vh;*/
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/1.0.1/trianglify.min.js"></script>
<div class="outer-wrapper">
  <canvas id="container1"></canvas>
  <div class="screen-container trianglify-container">
    <div class="container">
Lorem ipsum dolor sit amet, consectetur adipiscing elit... 
(Lengthy content continues...)
    </div>
  </div>
</div>

-- Same code, now with a shorter message --

var pattern = Trianglify({
      cell_size: 25,
      x_colors: 'Greens'
    });
    pattern.canvas(document.getElementById('container1'));
    setInterval(function() {
      // method to be executed;
      var pattern = Trianglify({
        cell_size: 25,
        x_colors: 'Greens'
      });
      pattern.canvas(document.getElementById('container1'));
    }, 1000);
I placed them both in a wrapper div with `min-height: 100%`. The div expands as the content grows, while the canvas fills the div.
.outer-wrapper{
  min-height: 100vh;
  position: relative;
}
canvas#container1 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.screen-container {
  /*min-height: 100vh;*/
  position: relative;
}
.trianglify-container {
  background-color: transparent;
  color: #fff;
  text-align: center;
  /*padding-top: 20vh;*/
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/1.0.1/trianglify.min.js"></script>
<div class="outer-wrapper">
  <canvas id="container1"></canvas>
  <div class="screen-container trianglify-container">
    <div class="container">
Short message
    </div>
  </div>
</div>

Answer №2

https://example.com/unique-link

Do you prefer it this way? I have adjusted the .screen-container to include the width of the canvas

.screen-container {
max-width: 100%;
position: absolute;
}

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

Place a "sticky" button directly below a second "sticky" navigation bar

Within my app file, I have customized components like an appbar and various page elements: const styles = theme => ({ appBar: { width:'100%', }, }); class App extends Component { render() { const {classes} = this.props; ...

Unable to display numerous bars on the x-axis in vue-chartjs

Having trouble displaying a stacked bar chart with two bars sharing a label on the x-axis. The issue is that the 2nd bar sits below the first one (if you hide the 2021 value, the 2022 bar will appear): var barChartData = { labels: ["January", "Febru ...

Jade fails to show image in route with parameter

Currently, I am utilizing express 4 and have images saved in the uploads directory. This is a snippet of my code: app.use(express.static(__dirname + '/uploads')); //This part works app.route('/') .get(function (req, res) { ...

Dynamic HTML Generation using ASP.NET

Below is the code snippet that needs to be optimized: <asp:TemplateField HeaderText="Item Data"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "ItemData1") %> <br />&nbsp;&nbsp; <%# D ...

Open the provided URL in the web browser

Is it possible to open the URL in the web browser? $(document).ready(function(){ $(document).on('click','#see',function(){ var ID = $("#rowid").val(); $.ajax({ type:'GET', url:&ap ...

Discover a revolutionary Android app that provides detailed indoor maps and step-by-step walking directions

I am looking to enhance a custom Google map by adding sidewalks for walking, while keeping all of its original features intact. Additionally, I want to create a detailed interior map of a building on a college campus, complete with classroom locations on ...

Utilizing NGINX as a reverse proxy for secure communication with Node.js

I'm currently running an NGINX server setup as a reverse-proxy server for a node application. I am now trying to enable HTTPS, but every time I attempt to access the site via HTTPS, I encounter a "502: Bad Gateway" error. server { listen 80; ...

Incorporating the ThreeJS Transform tool into the Autodesk Forge Viewer

Trying to implement ThreeJS Transform control into the Forge Viewer by following an informative tutorial: The current issue is being able to add the Transform Control successfully, but not being able to interact with it. I had to make a slight adjustment ...

Switching a Rails/Ajax form from create to update mode upon submission

While experimenting with a star ratings page, I encountered an issue where the form element remained in "Create" mode instead of updating to an "Update" method after submission. The rating form is ajaxified, but it lacks the functionality to dynamically sw ...

Immersive pop-up interface displaying a variety of embedded videos simultaneously

I am a beginner in JavaScript and I came across a CodePen that does exactly what I need, but it currently only works for one embedded video. What I aim to achieve is similar functionality, but with 6 videos. (function ($) { 'use strict'; ...

Struggling with getting my Vue-CLI app deployed on Heroku

After diligently following all the steps outlined in this tutorial: https://codeburst.io/quick-n-clean-way-to-deploy-vue-webpack-apps-on-heroku-b522d3904bc8 I encountered an error message when checking my app at: The error indicated: Method Not Allowed ...

How to Eliminate Image Flickering While Loading in a React Component

Currently, I am developing a React component that takes an imageUrl and displays it on a canvas with a deliberate 2-second delay to mimic loading time for larger images. However, I have encountered a problem: when the imageUrl changes in the parent compone ...

Assistance needed with looping through a JSON data structure

Hello, I am facing an issue after a query in PHP and converting the results to JSON using json_encode. The JSON data I have is: {"ga:visits":"59","ga:pageviews":"117","ga:timeOnSite":"4775.0","average_time_on_site_formatted":"0:01:20","pages_per_visit":"1 ...

Sending data between two elements when a jQuery event is triggered

As a JavaScript beginner, I am facing an issue where I need to push data from an h1 tag to a textarea. My website is built using WooCommerce and when a visitor clicks on a product, a chat box with the product title opens. Currently, I have successfully p ...

Utilizing the require function to implement an AngularJS Controller without having

I've been working with requireJS in my application. Every time I try to register a controller on my module, it gives me an error saying that the controller is not defined. Here's the code for my LoginController located in login.controller.js: f ...

JavaScript can be utilized to monitor outbound clicks effectively

I am currently working on implementing the code found at this link: Make a ping to a url without redirecting. The original poster is looking to ping a URL without opening multiple windows. My goal is to achieve the same functionality, but I also want to vi ...

Learn the methods for successfully transferring dynamic values from Angular to a jQuery script

This is the script that I have included in my HTML code: <div class="progress-bar"></div> <script type="text/javascript"> $('.progress-bar').gradientProgressBar({ value: $(this).attr('$scope.moodvalue'), ...

Is it possible for me to use ts files just like I use js files in the same manner?

So I recently stumbled upon TypeScript and found it intriguing, especially since I enjoy adding annotations in my code. The only downside is that I would have to change all my .js files to .ts files in order to fully utilize TypeScript's capabilities. ...

Trouble with top attribute functionality within animate function

Why does the top attribute in the animate function of JQuery not seem to work, while the opacity attribute functions correctly in the code snippet below? $(function() { $(window).on('scroll', function() { ...

tips for loading json data into jqgrid

Utilizing the struts2-jquery-jqgrid plugins, I have created a Grid with a filter-search feature. The Grid includes a drop-down list in the column assigned_user for filtering based on the selected option from the drop-down list. <s:url var="remoteurl" a ...