Advertisement
Guest User

swag

a guest
Jun 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. $(document).ready(function() {
  2. // Array of links to images
  3. var pictures = [
  4. "img/home/ateam.jpg",
  5. "img/home/electric.jpg"
  6. ];
  7.  
  8. var index = 0;
  9.  
  10. // Save the picture element
  11. var imgPic = $("#picture > img");
  12. var slidePic = $("#picture");
  13.  
  14. // Change picture
  15. imgPic.attr('src', pictures[0]);
  16. slidePic.css("background-image", "url(" + pictures[0] + ")");
  17.  
  18.  
  19. // If you click on the picture
  20. $("#picture").click(function() {
  21. });
  22.  
  23.  
  24. // If left button is pressed
  25. $("#leftBtn").click(function() {
  26. // Change index and cycle
  27. index--;
  28. if(index < 0)
  29. index = pictures.length - 1;
  30.  
  31. // Change picture
  32. imgPic.attr('src', pictures[index]);
  33. slidePic.css("background-image", "url(" + pictures[index] + ")");
  34. });
  35.  
  36. // If right button is pressed
  37. $("#rightBtn").click(function() {
  38. // Change index and cycle
  39. index++;
  40. if(index >= pictures.length)
  41. index = 0;
  42.  
  43. // Change picture
  44. imgPic.attr('src', pictures[index]);
  45. slidePic.css("background-image", "url(" + pictures[index] + ")");
  46.  
  47. });
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement