Frustrating empty gaps surrounding a complete canvas display on an HTML page

I've been scouring the internet for solutions to this problem, but I just can't seem to get it right when trying to implement them.

Everything seems to be functioning perfectly, except for that irritating white border that surrounds the canvas. Am I missing something?

Below is the code snippet in question:

var canvas = document.getElementById("canvas");
var x = window.innerWidth - 20;
var y = window.innerHeight - 20;

function resizeCanvas() {
    canvas.style.width  = x.toString() + 'px';
    canvas.style.height = y.toString() + 'px';
}

var granimInstance = new Granim({
    element: '#canvas',
    name: 'radial-gradient',
    direction: 'radial',
    opacity: [1, 1],
    isPausedWhenNotInView: true,
    states : {
        "default-state": {
            gradients: [
                ['#ffb347', '#ffcc33'],
                ['#83a4d4', '#b6fbff'],
                ['#9D50BB', '#6E48AA']
            ]
        }
    }
});

window.onresize = resizeCanvas;

resizeCanvas();
.canvas {
    position: absolute;
    display: block;
}

html, body {
    margin: 0;
    padding: 0;
    overflow: hidden
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/granim/1.0.6/granim.js"></script>
<!DOCTYPE html>
<html>
<head>
    <title>Announcements</title>
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <link rel="stylesheet" href="assets/css/club_meetingv2.css">
</head>
<body>
    <canvas id="canvas"></canvas>

<script type="text/javascript" src="assets/js/club_meetingv2.js"></script>
</body>
</html>

Answer №1

Is the annoying white border you mentioned located on the far right and bottom of the gradient?

If so, it could be caused by the initial lines of code:

var x = window.innerWidth - 20; var y = window.innerHeight - 20;

These lines are subtracting 20 pixels from the width and height at the right and bottom. By removing this, as shown in the codepen link below, you can achieve the desired outcome.

https://codepen.io/Robhern135/pen/NwxoMR

Answer №2

I believe I've discovered the resolution.

body {padding: 0}

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

Sending a PDF document to a function that specifically calls for a file location or URL

Currently, I am developing a web application for an online library where I need to extract metadata from PDF files that are uploaded. To achieve this, I am utilizing the nodejs libraries pdf.js-extract and multer-gridfs-storage for file uploads. However, I ...

Cleaning up HTML strings in Angular may strip off attribute formatting

I've been experimenting and creating a function to dynamically generate form fields. Initially, the Angular sanitizer was removing <input> tags, so I discovered a way to work around this by bypassing the sanitation process for the HTML code stri ...

What is the best method to execute two scripts within a single HTML file?

As a newcomer, I am facing an issue with using PrettyPhoto Lightbox and Flexslider in the same HTML file. Whenever I place PrettyPhoto at the bottom of the page, just before the closing body tag, it causes my Flex Slider to disappear and the PrettyPhoto li ...

Issues arise when attempting to affix the navigation bar to the top of the webpage

After running the code below, I noticed that my navbar is not behaving as expected and seems to be stuck in the middle of the screen instead of being fixed to the top. This is confusing for me because I have created navbars before that worked fine. Any ass ...

The screen reader is unable to interpret the text that is visible within the anchor tag

I have an Angular application with a dropdown menu implemented as shown below. When using the NVDA screen reader to navigate, only the content inside the aria-label attribute is being read when tab focused. However, I want it to also read the content (&ap ...

I'm struggling to resolve the issue I'm encountering with findOneAndUpdate. Can anyone offer guidance on how to

Attempting to modify a mongodb document using the findOneAndUpdate method. Experimented with various approaches to locating the document and restructuring the update operation. router.put( "/edit", [ auth, [ check("name", "Name is requi ...

Make sure to wait for the current operation to finish before moving onto the next one

In the primeData function within the datacontext, four queries are made to a back-end Web API service: function primeData(forceRefresh) { return (getLookups(forceRefresh) // this needs to complete before moving on .then(success)) ...

Learn the steps to transform your Magento 2 store into a Progressive Web App for seamless user experience

I am currently running a Magento 2 store and I am interested in implementing the PWA feature on it. ...

Could using 'require' in node.js lead to a memory leak issue?

I have been working on a program that experiences continuous heap growth. The program is quite simple - it repeatedly tries to load an external file (SyntaxError) using require. However, this external module fails to load due to a syntax error present in i ...

CSS Drop Shadow effect is failing to render properly

I tried creating a button with a neumorphism drop shadow effect, but it's not working as expected. The button just appears as a solid two-toned button. I'm wondering if I'm using the CSS incorrectly. Could my drop shadow values be wrong in r ...

The Angular2 view is failing to display updated data from a shared service

I've been struggling to show data from my shared service, but it's not displaying. Can someone please help me out? I've been stuck on this for the past few days. I've tried NgZone and ChangeDetectorRef, but they haven't worked for ...

Recognizing the click event on the checkbox within a <TableRow/> in ReactJS with MaterialUI

Using ReactJS and MaterialUI's component for tables, I have successfully created a table with two rows, each containing a checkbox. Now, the challenge is to create a method that can recognize when a checkbox is clicked and provide information about th ...

Animate an image element to smoothly slide in from the left while simultaneously fading into view using Javascript

I'm looking to achieve a specific effect using pure JavaScript, HTML, and CSS without the need for jQuery or other libraries. I want an element to fade in and smoothly move to the center of the page from the left after a button click event. My attemp ...

Unable to locate image in React framework

When attempting to display an image, I encountered a 404 error even though the folder containing it is being served properly. Code snippet from JSX file: render: function(){ ... return <button type="button" id="powerButton" onClick={this.someFun}>& ...

Prevent accordion expansion triggered by the More button click

When the More button is clicked, it should NOT expand and collapse. https://i.sstatic.net/toV1b.gif If the accordion initial state is open, it must stay open even if button is clicked, if initial state is collapsed then after the more button the accordio ...

Navigating within a React application - rendering JSX components based on URL parameters

As I work on developing a web-app with a chapter/lesson structure, I have been exploring ways to handle the organization of lessons without storing HTML or React code in my database. One idea I had was to save each lesson as a .jsx file within a folder str ...

Struggling to Position Advertisement in CSS

I've been struggling to properly center a div using CSS. Adding text-align: center; doesn't seem to do the trick. The issue can be found in the top advert on this website: . Do you have any suggestions? Here's some sample code: HTML: &l ...

Exploring tools to grasp the intricacies of HTML page structure

Can you recommend any alternatives to Firebug for analyzing the structure of my HTML code? If so, please provide details on what sets these tools apart from Firebug in terms of functionality. ...

Implementing the rotation of an element using 'Transform: rotate' upon loading a webpage with the help of Jquery, Javascript, and

A div element designed to showcase a speedometer; <div class="outer"> <div class="needle" ></div> </div> The speedometer animates smoothly on hover; .outer:hover .needle { transform: rotate(313deg); transform-origin: ce ...

Why is this component not functioning properly?

I am struggling with making a function to add a component dynamically when I click a button, similar to the code below. However, my attempt at creating a separate method for adding the component instead of using an inline expression is not working. Can som ...