Logo
  Sunday, May 20, 2012
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

HTML5 Background Patterns  
Images can be used throughout web application, but sometimes it is useful to set images as backgrounds. Currently this option is possible with the help of CSS files. HTML5 makes this possible as well. We use HTML5 canvas API in order to accomplish this.

In order to set background image for a path stroke of a fill, all we need is to set an image as our repeatable patter on a path stroke of a fill.

Code example below will show you have it is done in HTML5

<script>

    function backgroundPatternExample(context) {

        var myImage = new Image();

        myImage.src = 'image.jpg';

        context.strokeStyle = context.createPatter(myImage, 'repeat');

        context.lineWidth = 50;

        context.stroke();

    }

</script>

There are different types of image repeat patters in HTML5. They are explained in the following list:

  • repeat – image is applied in all directions
  • repeat-x – image is repeated along x-dimension
  • repeat-y - image is repeated along y-dimension
  • no-repeat – image displayed only one time
As you can see HTML5 background patters is powerful set of functionality provided with the new version of HTML.
Print HTML5 Background Patterns Bookmark HTML5 Background Patterns

Related Articles  
HTML5 canvas browser compatibility
HTML5 is not official and mandated version of HTML and not every browser vendor supports it. You need to be aware of ...
Drawing Curves in HTML5
HTML5 allows you to draw curves on HTML5 canvas. They way to do it is with the help of paths.
HTML5 Canvas Coordinates
The HTML5 canvas has X-Axis and Y-Axis and is two dimensional. It has starting point in the upper-left corner which ...
Working with underlying pixels in the HTML5 canvas
HTML5 developer can gain access to individual pixel in the canvas. The way it is accomplished is via a numerical array.
HTML5 canvas transformation
Canvas transformation is generally used to set up comprehensive canvas. It can be overkill if you want to create simple ...
Creating Shadow Effect with HTML5
HTML5 shadows are controlled by several operations available in HTML5 arsenal of operations. The shadow effect can be ...
More