Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //HTML
- <div class="cover-image-wrap-portf">
- <img src="img/pixel.jpg" class="cover-image" alt="alt">
- </div>
- //CSS
- .cover-image-wrap
- position: absolute
- top: 0
- right: 0
- left: 0
- bottom: 0
- img.cover-image
- position: absolute
- left: 0
- top: 0
- height: 100%
- width: 100%
- object-fit: cover
- .cover-image-wrap.fallback, .cover-image-wrap-portf.fallback
- background-size: cover
- background-position: center center
- img.cover-image // hide image if object fit is not supported - opacity to 0 for the link area
- opacity: 0
- //JS
- if ( ! Modernizr.objectfit ) {
- $('.cover-image-wrap-portf').each(function () {
- var $container = $(this),
- imgUrl = $container.find('img.cover-image').attr('data-original');
- if (imgUrl) {
- $container
- .css('backgroundImage', 'url(' + imgUrl + ')')
- .addClass('fallback');
- }
- });
- $('.cover-image-wrap').each(function () {
- var $container = $(this),
- imgUrl = $container.find('img.cover-image').prop('src');
- if (imgUrl) {
- $container
- .css('backgroundImage', 'url(' + imgUrl + ')')
- .addClass('fallback');
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement