Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*jslint browser: true, devel: true*/
  2. /*global $, jQuery*/
  3.  
  4. // Images Array
  5. var images = ['images/img1.jpg', 'images/img2.jpg', 'images/img3.jpg', 'images/img4.jpg', 'images/img5.jpg', 'images/img6.jpg', 'images/img7.jpg', 'images/img8.jpg'];
  6. var lastSelected = false;
  7.  
  8.  
  9. function closeImage(image) {
  10.     'use strict';
  11.     image.animate({
  12.         opacity: 0,
  13.         width: 0,
  14.         height: 0
  15.     }, 1000, function () {
  16.         $(this).remove();
  17.     });
  18.  
  19. }
  20.  
  21. function showImage(image) {
  22.     'use strict';
  23.     image.animate({
  24.         'max-width': '400px',
  25.         'max-height': '400px',
  26.         'margin-top': '0px',
  27.         opacity: 1
  28.     }, 1000);
  29. }
  30.  
  31. function onThumbClick() {
  32.     'use strict';
  33.  
  34.     // Get Instance of selected image
  35.     var image = $(this).find('img');
  36.     // Clone this instance amd add the thumbClone class to it
  37.     var clone = image.clone().addClass('thumbClone');
  38.  
  39.     // Instance the image holder and add the thumb clone to it
  40.     var imageHolder = $('#imageHolder');
  41.     var currentImage = imageHolder.find('img');
  42.     if (image.attr('id') != currentImage.attr('id')) {
  43.         imageHolder.append(clone);
  44.         showImage(clone);
  45.         if (lastSelected != false)
  46.             closeImage(lastSelected);
  47.         lastSelected = clone;
  48.     }
  49.     $('.thumbnail').removeClass('selected');
  50.     $(this).addClass('selected');
  51. }
  52.  
  53. $(document).ready(function () {
  54.     'use strict';
  55.  
  56.     // Show thumbnails to the screen
  57.     images.forEach(function (singleImage) {
  58.         // Inner scope vars
  59.         var thumbnail = $('<div>'),
  60.             image = $('<img>');
  61.  
  62.         // Set the image src
  63.         image.attr('src', singleImage).attr('id', "img" + images.indexOf(singleImage));
  64.  
  65.         // Build the thumbnail using the chaning function of a jquery object
  66.         thumbnail.addClass('thumbnail').append(image).appendTo('#thumbnails').css('opacity', 0.0).fadeTo(2000 + images.indexOf(singleImage) * 500, 0.5, function () {
  67.             $(this).click(onThumbClick);
  68.             $(this).css('cursor', 'pointer');
  69.         });
  70.  
  71.     });
  72.  
  73.     // Fade in the message text
  74.     $('#message').fadeTo(2000 + images.length * 500, 1.0);
  75.  
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement