Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:11:29+00:00 2026-06-02T09:11:29+00:00

I created a canvas element and I’m using javascript to make it as big

  • 0

I created a canvas element and I’m using javascript to make it as big as possible in the viewport, while maintaining the aspect ratio.

When you rotate the iPad, the device first rotates the page and only after that launches the resize event.

The problem is, if you come from landscape (about 800px wide) to portrait (about 400px), a part of the body is not being displayed, because the resize didn’t happen yet at that moment. After this, the resize event resizes the canvas to the correct size, but then a part of the canvas (& document) is still outside the viewport.

So basically the problem exists because the resize event only launches after the iPad already cut off a part of the body on both sides because the body is too wide.

I could fix this by setting a margin to the canvas to compensate, but it’s a dirty solution… does anyone have a better suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:11:29+00:00Added an answer on June 2, 2026 at 9:11 am

    This could also be considered a dirty solution, but in the past I have used a setTimeout to deal with this issue, and it seems to always be reliable.

    window.onorientationchange = function() {
        canvasResize();
    }
    
    function canvasResize() {
        window.setTimeout(function () {
            //Your code here based on new size
        }, 100);
    }
    

    Or if you are looking for a slightly less dirty solution, you should be able to just keep track of the viewport width yourself, and then wait until that changes to do your updates. Add to your script somewhere:

    var viewportWidth = window.innerWidth;
    

    And change canvasResize:

    function canvasResize() {     
        if(window.innerWidth != viewportWidth) {//Dimensions have changed for sure
            viewportWidth = window.innerWidth; //Update viewportWidth for future use
            //Your code here based on new size
        }
        else {
            //Delay and try again
            window.setTimeout(function () {
                canvasResize();
            }, 100);
        }
    }
    

    Both of are pretty quick and dirty, and I’d be interested if there’s a more elegant solution, but I haven’t found one yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Facebook canvas app. I tried using the app as a user.
I'm trying to resize a HTML5 canvas element using jQuery. (NOTICE: Not the objects
I'm trying to change the size of an HTML5 canvas element created by the
Is it possible to set the width and height of a canvas element and
I have a function that rotates an object using the canvas element. When I
Is there a JavaScript library that simulates the canvas element but instead of creating
I have converted the contents of a canvas element to data (URI Scheme) using
I am playing with the HTML5 canvas element, using JS to draw some rectangles
Currently, when using the HTML5 canvas element, stroked paths have slightly feathered edges. Here
I'm using Three.js to create some 3D graphics using webgl in a canvas element.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.