Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //Problem: User when clicking on image goes to a dead end
  2. //Solution: Create an overlay with the large image - Lightbox
  3. $(document).ready(function() {
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. var $overlay = $('<div id="overlay"></div>');
  11. var $image = $("<img>");
  12. var $caption = $("<p></p>");
  13.  
  14. //An image to overlay
  15. $overlay.append($image);
  16.  
  17. //A caption to overlay
  18. $overlay.append($caption);
  19.  
  20. //Add overlay
  21. $("body").append($overlay);
  22.  
  23. //Capture the click event on a link to an image
  24. $("#imageGallery a").click(function(event) {
  25. event.preventDefault();
  26. var imageLocation = $(this).attr("href");
  27. //Update overlay with the image linked in the link
  28. $image.attr("src", imageLocation);
  29.  
  30. //Show the overlay.
  31. $overlay.show();
  32.  
  33.  
  34.  
  35. //Get child's alt attribute and set caption
  36. var captionText = $(this).children("img").attr("alt");
  37. $caption.text(captionText);
  38. });
  39.  
  40. //When overlay is clicked
  41. $overlay.click(function() {
  42. //Hide the overlay
  43. $overlay.hide();
  44. });
  45.  
  46.  
  47. $("#autumn").click(function() {
  48.  
  49.  
  50. $("#images").load("autumn.html #autumn > *");
  51. });
  52.  
  53.  
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement