Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE HTML>
<html>
    <head>
        <style>
            body {
                margin: 0px;
                padding: 0px;
            }
            
            #myCanvas {
                border: 1px solid #9C9898;
            }
        </style>
        <script>
            window.onload = function(){
                var canvas = document.getElementById("myCanvas");
                var context = canvas.getContext("2d");
                
                var imageObj = new Image();
                imageObj.onload = function(){
                  // Try to change the last parameter to repeat-x, repeat-y, or
                  //no-repeat
                    var pattern = context.createPattern(imageObj, "repeat");
                    
                    context.rect(10, 10, canvas.width - 20, canvas.height - 20);
                    context.fillStyle = pattern;
                    context.fill();
                };
              
                imageObj.src = "http://www.html5canvastutorials.com/demos/tutorials/html5_canvas_patterns/wood-pattern.png";
            };
        </script>
    </head>
    <body onmousedown="return false;">
        <canvas id="myCanvas" width="578" height="200">
        </canvas>
    </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers