Wednesday, October 15, 2014

JQuery based Simple Image Slider

To slide collection of images one by one, we are here using simple JQuery script.

Add following code in the space where you want to show images to slide..

<div>     
    <image ID="img1"  src="ImageGallery/1.jpg" Height="331px" width="100%" />    
</div>
<script type="text/javascript">
        var i = 1;
        function fun() {
            i++;
            document.getElementById("img1").src = "ImageGallery/" + i + ".jpg";
            if (i == 5) //here number of images i want to display in the slide show
            { i = 0; }
        }
        setInterval("fun()", 4000);
</script>  


Description:
Here image gallery has 5 images. Default image is 1.jpg. This image will appear on page load. Image will change after 4 seconds.