Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Canvas dynamic size - height constantly increasing

I want a canvas to fit its parent so I created a simple script:

<script>
    $(document).ready(() => {
        const canvas = document.getElementById('main-canvas');

        canvas.width = $('#canvas-container').width();
        canvas.height = $('#canvas-container').height();
        canvas.style.width = $('#canvas-container').width();
        canvas.style.height = $('#canvas-container').height();

        $(window).resize(() => {
            canvas.width = $('#canvas-container').width();
            canvas.height = $('#canvas-container').height();
            canvas.style.width = $('#canvas-container').width();
            canvas.style.height = $('#canvas-container').height();
        });
    });
</script>

The problem is that when I resize my browser window (Chrome), the height is not set correctly but constantly increasing. The more I resize the window the higher the canvas gets. Why is this happening? It also happens when I use offsetWidth and offsetHeight or the canvas instead of the container both with size functions or offset-size.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!