Create a Slideshow Image Gallery Using HTML5

Introduction

 
This is a simple application for beginners that shows how to create a slideshow image gallery using HTML 5, JQuery and CSS tools. We know that HTML 5 is the advanced version of HTML. Basically HTML 5 can be used to develop 3D applications. This article is intended to help with the use of HTML5 tools to develop slideshow image gallery applications. CSS is the acronym for Cascading Style Sheet that is used for design. CSS defines how HTML elements are to be displayed. Canvas is an important tag of an HTML 5 that is used to show the image and text in an HTML 5 application. I hope this article helps to develop a slideshow image gallery using HTML 5, JQuery and CSS tools.
 
Step 1: First open an HTML editor such as Notepad.
  • Open start->Notepad.
  • The name of the editor is "Gallery".
wakakakakak.gif
 
Step 2: Create a Folder on a desktop.
  • Right-click on desktop->new->Folder.
  • the name of the folder is "Tom".
folder.gif
 
Step 3: Open Visual Studio.
  • Go to file -> New->Projects.
  • Create an ASP. NET Web Application.
  • Name of "Image.aspx".
new.gif
 
webapplication.gif
 
Step 4: Add an HTML file to your web application.
  • Right-click on Solution Explorer.
  • Add->add new item->HTML form.
  • The Name of the HTML form is "slider.html".
html.gif
 
Step 5: Add a folder to your web application.
  • Right-click on Solution Explorer.
  • Add->add new folder.
  • The Name of the folder is "Gallery".
image folder.gif
 
Step 6: Add items in the image folder.
  • Right-click on the image folder.
  • Add->add Existing item.
  • After that add item in folder.
11111111111111111.gif
 
Step 7:Now in this step we define a CSS file named Photo1.css. In CSS we define all properties of sliders; that is background, border, margin, height, width, position, display, etc. 
 
Code
  1. body  
  2.    {  
  3.        color:Green;  
  4.        background:url('img/bg.jpg'repeat-x #CC99FF;  
  5.        font:13px "Lucida Sans Unicode",Arial;  
  6.       }  
  7.  #SLIDE  
  8.     {  
  9.        background-color:#F5F5F5;  
  10.        border:1px solid #FFFFFF;  
  11.        height:340px;  
  12.        margin:150px auto 0;  
  13.        position:relative;  
  14.        width:640px;  
  15.        -moz-box-shadow:0 0 22px #111;  
  16.        -webkit-box-shadow:0 0 22px #111;  
  17.        box-shadow:0 0 22px #111;  
  18.         }  
  19.  #SLIDE ul  
  20.     {  
  21.        height:320px;  
  22.        left:10px;  
  23.        list-style:none outside none;  
  24.        overflow:hidden;  
  25.        position:absolute;  
  26.        top:10px;  
  27.        width:620px;  
  28.      }  
  29.   #SLIDE li  
  30.     {  
  31.        position:absolute;  
  32.        display:none;  
  33.        z-index:10;  
  34.        }  
  35.   #SLIDE li:first-child  
  36.     {  
  37.        display:block;  
  38.        z-index:1000;  
  39.      }  
  40.   #SLIDE .slideActive  
  41.    {  
  42.        z-index:1000;  
  43.        }  
  44.   #SLIDE canvas{  
  45.        display:none;  
  46.        position:absolute;  
  47.        z-index:100;  
  48.      }  
  49.   #SLIDE .arrow  
  50.    {  
  51.        height:86px;  
  52.        width:60px;  
  53.        position:absolute;  
  54.        top:50%;  
  55.        margin-top:-43px;  
  56.        cursor:pointer;  
  57.        z-index:5000;  
  58.      }  
  59.   #SLIDE .previous{ background-position:left top;left:0;}  
  60.   #SLIDE .previous:hover{ background-position:left bottom;}  
  61.   #SLIDE .next{ background-position:right top;right:0;}  
  62.   #SLIDE .next:hover{ background-position:right bottom;} 
Step 8: Now in this step we set a path of a image in a div.
 
Code
  1. <div id="slideshow">  
  2.     <ul class="slides">  
  3.     <li><img src="Gallery/2aaaaaaa.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  4.     <li><img src="Gallery/143392-30741-19_10_13---Spring_web.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  5.     <li><img src="Gallery/c-sharpcorner.com.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  6.     <li><img src="Gallery/1.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  7.     <li><img src="Gallery/2.jpg" width="620" height="320" alt="Turrimetta Beach - Dawn" /></li>  
  8.     <li><img src="Gallery/3.jpg" width="620" height="320" alt="Power Station" /></li>  
  9.     <li><img src="Gallery/4.jpg" width="620" height="320" alt="Colors of Nature" /></li>  
  10.     </ul>  
  11.     <span class="arrow previous"></span>  
  12.     <span class="arrow next"></span>  
  13. </div> 
image.gif
 
Step 9: Now we have used a js file named galary.js. In the js file, we set a sliding functionality.
 
Code
  1. function createcanOverlay(image) {  
  2.    var can = document.createElement('can'),  
  3.        canContext = can.getContext("2d");  
  4.        can.width = slideshow.width;  
  5.        can.height = slideshow.height;  
  6.        canContext.drawImage(image, 0, 0);  
  7.        var Img = canContext.getImg(0, 0, can.width, can.height),  
  8.        data = Img.data;  
  9.        for (var i = 0, z = data.length; i < z; i++) {  
  10.        data[i] = ((data[i] < 128) ? (2 * data[i] * data[i] / 255) : (255 - 2 * (255 - data[i]) * (255 - data[i]) / 255));  
  11.        data[++i] = ((data[i] < 128) ? (2 * data[i] * data[i] / 255) : (255 - 2 * (255 - data[i]) * (255 - data[i]) / 255));  
  12.        data[++i] = ((data[i] < 128) ? (2 * data[i] * data[i] / 255) : (255 - 2 * (255 - data[i]) * (255 - data[i]) / 255));  
  13.        ++i;  
  14.            }  
  15.        canContext.putImg(Img, 0, 0);  
  16.        image.parentNode.insertBefore(can, image);  
  17.     }  
  18. }); 
Step 10: The complete code of the application is given below.
 
Code
  1. <html>  
  2.   <head>  
  3.   <title>Image Slider Demo</title>  
  4.   <link rel="stylesheet" type="text/css" href="photo1.css" />  
  5.   <body>  
  6.   </head>  
  7.   <div id="slideshow">  
  8.     <ul class="slides">  
  9.     <li><img src="Gallery/2aaaaaaa.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  10.     <li><img src="Gallery/143392-30741-19_10_13---Spring_web.jpg" width="620" height="320" alt="Marsa Alam underawter close up"    /></li>  
  11.     <li><img src="Gallery/c-sharpcorner.com.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  12.     <li><img src="Gallery/1.jpg" width="620" height="320" alt="Marsa Alam underawter close up" /></li>  
  13.     <li><img src="Gallery/2.jpg" width="620" height="320" alt="Turrimetta Beach - Dawn" /></li>  
  14.     <li><img src="Gallery/3.jpg" width="620" height="320" alt="Power Station" /></li>  
  15.     <li><img src="Gallery/4.jpg" width="620" height="320" alt="Colors of Nature" /></li>  
  16.     </ul>  
  17.     <span class="arrow previous"></span>  
  18.     <span class="arrow next"></span>  
  19.   </div>  
  20.   <script src="Scripts/galary.js"></script>  
  21.   <h1>Tom Develop a Slider image</h1>   
  22.   </body>  
  23. </html>  
Step 11: The followingshows an image of the complete application.
 
compete image.gif
 
Step 12: Press Ctrl + F5 to run the application in a browser. 
 
Output
 
1.gif
 
Click a corner of the image; after that change an image one by one.
 
3.gif
 
2.gif
 
Resources
 
Here are some useful resources :


Similar Articles