Thursday 14 August 2014

Image Slideshow Using PHP and simple Jquery

Step 1:Creating our style to beautify our slideshow

to create, open your php editor and paste the code bellow and save it as "slideshow.php."


  1. <html lang="en">



  2. <head>



  3. <title>Simplest jQuery Slideshow</title>



  4.  



  5. <style>



  6. body {font-family:Arial, Helvetica, sans-serif; font-size:12px;}



  7.  



  8. .fadein {



  9. position:relative; height:332px; width:500px; margin:0 auto;



  10. background: url("slideshow-bg.png") repeat-x scroll left top transparent;



  11. padding: 10px;



  12. }



  13. .fadein img { position:absolute; left:10px; top:10px; }



  14. </style>



Step 2: Creating and linking our jquery

To create, copy and paste the code below after the style tag in the file "slideshow.php".


  1. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>



  2. <script>



  3. $(function(){



  4. $('.fadein img:gt(0)').hide();



  5. setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 3000);



  6. });



  7. </script>



Step 3: Creating the div tag where the images display

Copy and paste the code below after the script tag of "slideshow.php".


  1. </head>



  2. <body>



  3. <div class="fadein">



  4. <img src="http://chictraveler.wpengine.netdna-cdn.com/wp-content/uploads/2010/09/Picture-91-500x332.png">



  5. <img src="http://sevillespain.info/wp-content/uploads/2012/02/Casa-De-Carmona-Hotel-Seville-casa_de_carmona_galeria_mr_1200-500x332.jpg">



  6. <img src="http://hereelsewhere.com/wp-content/uploads/2012/06/Chambre22-500x332.jpeg">



  7. <img src="http://www.worlddesignhotels.com/wp-content/uploads/407/X%20Ordinary%20Room-500x332.jpg">



  8. <img src="http://armywife101.com/wp-content/uploads/2012/09/DoubleTree-Suites-by-Hilton-exterior-photo-Downtown-Disney-Resort-Area-Hotels-500x332.jpg">



  9. </div>



  10. </body>



  11. </html>



the summarize code will look like the code below


  1. <html lang="en">



  2. <head>



  3. <title>Simplest jQuery Slideshow</title>



  4.  



  5. <style>



  6. body {font-family:Arial, Helvetica, sans-serif; font-size:12px;}



  7.  



  8. .fadein {



  9. position:relative; height:332px; width:500px; margin:0 auto;



  10. background: url("slideshow-bg.png") repeat-x scroll left top transparent;



  11. padding: 10px;



  12. }



  13. .fadein img { position:absolute; left:10px; top:10px; }



  14. </style>



  15.  



  16. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>



  17. <script>



  18. $(function(){



  19. $('.fadein img:gt(0)').hide();



  20. setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 3000);



  21. });



  22. </script>



  23.  



  24. </head>



  25. <body>



  26. <div class="fadein">



  27. <img src="http://chictraveler.wpengine.netdna-cdn.com/wp-content/uploads/2010/09/Picture-91-500x332.png">



  28. <img src="http://sevillespain.info/wp-content/uploads/2012/02/Casa-De-Carmona-Hotel-Seville-casa_de_carmona_galeria_mr_1200-500x332.jpg">



  29. <img src="http://hereelsewhere.com/wp-content/uploads/2012/06/Chambre22-500x332.jpeg">



  30. <img src="http://www.worlddesignhotels.com/wp-content/uploads/407/X%20Ordinary%20Room-500x332.jpg">



  31. <img src="http://armywife101.com/wp-content/uploads/2012/09/DoubleTree-Suites-by-Hilton-exterior-photo-Downtown-Disney-Resort-Area-Hotels-500x332.jpg">



  32. </div>



  33. </body>



  34. </html>



Congratulation, you've been successfully created your image slideshow with a very few lines of code.
I also included the file in this tutorial. you can download the file and run it on your computer.
Hope this code helps you.

No comments:

Post a Comment