Introduction
In this article we will create a simple Image Slider in which the image can be scrolled in both directions (X and Y) with the slider like this:
In this example, we will use a Canvas, that will be used as a container of our images in the Image Slider. Here we will use the drawImage() method that is used to draw our Image in the Canvas.
Step 1: So first we will create a Canvas using the <canvas> tag like this:

- <canvas id="myCanvas" width="1200" height="800"></canvas>
Step 2: Now we will use the Images for our Image Slider:
- <img id="img1" src="Desert.jpg" style="display:none;" />
- <img id="img2" src="Hydrangeas.jpg" style="display:none;" />
- <img id="img3" src="Jellyfish.jpg" style="display:none;" />
- <img id="img4" src="Koala.jpg" style="display:none;" />
- <img id="img5" src="Lighthouse.jpg" style="display:none;" />
- <img id="img6" src="Penguins.jpg" style="display:none;"/>
- <img id="img7" src="Chrysanthemum.jpg" style="display:none;"/>
- <img id="img8" src="Tulips.jpg" style="display:none;" />
Here we will set the display property of the images so it can't be visible.
Step 3: Now we will write the JavaScript function Show():
- <script language="javascript">
- var i = 1, x = 100, y = 100, j = 0;
- var img = new Image();
- var imgsrc;
- function Show() {
- var canvas = document.getElementById('myCanvas');
- var context = canvas.getContext('2d');
- }
- </script>

Gowtham RajamanickamPosted Mar 13, 2015, 2:16 AM
great and simple...