Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //HTML
  2. <div class="cover-image-wrap-portf">
  3. <img src="img/pixel.jpg" class="cover-image" alt="alt">
  4. </div>
  5.  
  6. //CSS
  7. .cover-image-wrap
  8. position: absolute
  9. top: 0
  10. right: 0
  11. left: 0
  12. bottom: 0
  13.  
  14. img.cover-image
  15. position: absolute
  16. left: 0
  17. top: 0
  18. height: 100%
  19. width: 100%
  20. object-fit: cover
  21.  
  22. .cover-image-wrap.fallback, .cover-image-wrap-portf.fallback
  23. background-size: cover
  24. background-position: center center
  25. img.cover-image // hide image if object fit is not supported - opacity to 0 for the link area
  26. opacity: 0
  27.  
  28.  
  29. //JS
  30. if ( ! Modernizr.objectfit ) {
  31. $('.cover-image-wrap-portf').each(function () {
  32. var $container = $(this),
  33. imgUrl = $container.find('img.cover-image').attr('data-original');
  34. if (imgUrl) {
  35. $container
  36. .css('backgroundImage', 'url(' + imgUrl + ')')
  37. .addClass('fallback');
  38. }
  39. });
  40.  
  41. $('.cover-image-wrap').each(function () {
  42. var $container = $(this),
  43. imgUrl = $container.find('img.cover-image').prop('src');
  44. if (imgUrl) {
  45. $container
  46. .css('backgroundImage', 'url(' + imgUrl + ')')
  47. .addClass('fallback');
  48. }
  49. });
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement