Create a Web Slideshow using JQuery
The final result of this blog post is a web accessible slideshow created using HTML, CSS and JavaScript (the JQuery library) as in this page
Step 1: The HTML Content
In Step 1, we add the HTML markup for the slides' contents within the <body> of the webpage. There is no limit on the number of slides.
<!-- Slideshow HTML --> |
Step 2: The CSS Content
The next step, is to add the CSS content within the <head> element of the webpage that consists of the slideshow style rules. These rules can be modified according to the need; for example, the height and width rules of the slides, etc. Two images named 'control_left.jpg' and 'control_right.jpg' with height equal to the height of #slideshow are required.
<style type="text/css"> #slideshow { #slideshow #slidesContainer { #slideshow #slidesContainer .slide { .control { #leftControl { #rightControl { .slide p { .slide h2 { --> |
Step 3: The JavaScript content
In this step, we insert the JavaScript code to manipulate the DOM for the slideshow effect. Our code is dependent on the JQuery JavaScript library, therefore the library will be linked as well.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ // Remove scrollbar in JS // Wrap all .slides with #slideInner div // Set #slideInner width equal to total width of all slides // Insert controls in the DOM // Hide left arrow control on first load // Create event listeners for .controls clicks // manageControls: Hides and Shows controls depending on currentPosition </script> |
The web-based slideshow is now ready. Clicking on the right/left arrow images have the effect of moving the slides right/left one at a time.
Keep Reading...