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 8184979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:41:21+00:00 2026-06-07T01:41:21+00:00

How can I resize a canvas with javascript/jquery? Resizing using the css function and

  • 0

How can I resize a canvas with javascript/jquery?

Resizing using the css function and applying it to the canvas element just stretches the content as if you were stretching an image.

How would I go about doing this without the stretching?

http://jsfiddle.net/re8KU/4/

  • 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-07T01:41:23+00:00Added an answer on June 7, 2026 at 1:41 am

    Make a function that does the drawing, then re-draw whenever something changes that requires it (like a page resize, etc). Try it out

    Make sure you set the context.canvas.width/height, not CSS width/height. Also note that setting the size clears the canvas.

    How I would write it:

    (function(){
        var c = $("#canvas"), 
            ctx = c[0].getContext('2d');
    
        var draw = function(){
            ctx.fillStyle = "#000";
            ctx.fillRect(10,10,50,50);   
        };
    
        $(function(){
            // set width and height
             ctx.canvas.height = 600;
             ctx.canvas.width = 600;
            // draw
            draw();
    
            // wait 2 seconds, repeate same process
            setTimeout(function(){
                ctx.canvas.height = 400;
                ctx.canvas.width = 400;
                draw();
            }, 2000)
        });
    })();
    

    ​

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

Sidebar

Related Questions

I've got an HTML5 canvas element in which a user can dynamically move, resize,
Why does canvas stretch the contents when you resize it and how can I
I'm trying to figure out how to resize a child canvas but I can't
How can I resolve the resize of facebook app on IE ? the FB.Canvas.setSize()
I have a custom canvas that I can drop controls on, move, and resize.
My project is a canvas (not HTML5 element) where a user can add images,
How can I duplicate the content of a resized canvas inside another one? If
Now I can draw rectangle in canvas using a mousedown and mousemove events I
I am using canvas to manipulate images, crop, resize and optimise before uploading them.
I have a rectangle on canvas. I can already moving this object using with

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.