Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. ( function( $ ) {
  2.  
  3. // Override default behavior
  4. $('.woocommerce-main-image').on('click', function( event ) {
  5. event.preventDefault();
  6. });
  7.  
  8. var thumblink = $( '.thumbnails .zoom' ); // Find the individual thumbnail images
  9.  
  10. thumblink.first().addClass('active'); // Add our active class to the first thumb which will already be displayed on page load.
  11.  
  12. thumblink.on( 'click', function( event ) {
  13.  
  14. event.preventDefault(); // Override default behavior on click.
  15.  
  16. var thumb = $(this).find('img'); // We'll generate all our attributes for the new main image from the thumbnail.
  17. var photo_fullsize = thumb.attr('src').replace('-200x200',''); // The new main image url is formed from the thumbnail src by removing the dimensions appended to the file name.
  18. var photo_srcset = thumb.attr('srcset'); // srcset attributes are associated with thumbnail img. We'll need to also change them.
  19. var alt = thumb.attr('alt'); // Retrieve alt attribute for use in main image.
  20.  
  21. // If the selected thumb already has the .active class do nothing.
  22. if ($(this).hasClass('active')) {
  23. return false;
  24. } else {
  25.  
  26. thumblink.removeClass('active'); // Remove .active class from previously selected thumb.
  27.  
  28. $(this).addClass('active'); // Add .active class to new thumb.
  29.  
  30. // Fadeout main image and replace various attributes with those defined above. Once the image is loaded we'll make it visible.
  31. $('.woocommerce-main-image img').css( 'opacity', '0' ).attr('src', photo_fullsize).attr('srcset', photo_srcset).attr('alt', alt).load(function() {
  32. $(this).animate({ opacity: 1 });
  33. });
  34. return false;
  35. }
  36. });
  37. } )( jQuery );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement