fancybox icon indicating copy to clipboard operation
fancybox copied to clipboard

[RESOLVED] : Adding background image or full bleed images

Open amyth91 opened this issue 9 years ago • 3 comments

#227

Is there a way of making the images full bleed, despite the actual image dimensions.

Currently the images are scaled down to fit the parent, but I am trying to get the image to be full bleed, something like "background-size:cover"

Thanks

amyth91 avatar Apr 10 '17 22:04 amyth91

#1357 Found a solution.

Doing this will make the container 100% : http://jsfiddle.net/RyTcS/embedded/result/

But: .fancybox-placeholder will be set to display none and image will be it's normal size.

Add this extra css to make it full bleed.

.fancybox-placeholder {
    display: block !important;
    position: relative;
    height: 100%;
}


  .fancybox-placeholder  img {
        object-fit: cover;
    }

** object-fit:cover is the answer, this makes the images behave the same way as background-size:cover ** See usage and compatibility: http://caniuse.com/#search=object-fit

amyth91 avatar Apr 10 '17 23:04 amyth91

You can trick the script to show images as html content:

$(document).on('beforeLoad.fb', function( e, instance, current ) {
    current.type = 'html';
    current.content = '<div class="fancybox-image" style="background-image:url(' + current.src + '); background-size: cover; background-position:50% 50%;background-repeat:no-repeat;height:100%;width:100%;" /></div>';
});

See demo - http://codepen.io/fancyapps/pen/NjKxpQ

Maybe some day this will be included in the core.

Duplicate of #227

fancyapps avatar Apr 11 '17 07:04 fancyapps

It would be really nice to have it in 3.1 - blurred images are not cool

Eldenroot avatar Apr 13 '17 19:04 Eldenroot