Dynamically resize canvas window with javascript/jquery?

后端 未结 3 1048
野的像风
野的像风 2020-12-15 19:04

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 str

3条回答
  •  孤城傲影
    2020-12-15 19:42

     (function($) {  
            $.fn.extend({  
                //Let the user resize the canvas to the size he/she wants  
                resizeCanvas:  function(w, h) {  
                    var c = $(this)[0]  
                    c.width = w;  
                    c.height = h  
                }  
            })  
        })(jQuery)
    

    Use this little function I created to take care of resizing on the go. Use it this way --

    $("the canvas element id/class").resizeCanvas(desired width, desired height)
    

提交回复
热议问题