fancyapps / ui

A library of JavaScript UI components, includes the best lightbox - Fancybox5
https://fancyapps.com/
Other
814 stars 98 forks source link

Gap between border and image #70

Closed IMC-GER closed 1 year ago

IMC-GER commented 3 years ago

Hi!

When I add a border to the image, is there a gap between the border and the image. https://fancyapps.com/playground/BD

fancyapps commented 3 years ago

Hi,

Sorry, adding a border to content is not currently supported. But you can create a border effect using this snippet:

.fancybox__container .fancybox__content {
  box-sizing: content-box;
  padding: 1rem;
  background: #fff;
}

See this demo - https://fancyapps.com/playground/vo

IMC-GER commented 3 years ago

Thanks! This helps a lot.

robfaas commented 3 years ago

I would like the possibility to set Image to zoom: true. But when I do, there is an ugly delay between (dis)appearance of container-with-background and image.

fancyapps commented 3 years ago

@robfaas Sorry, I do not understand, there is no delay between click and zoom animation (unless you have defined double click event, in such case there is a delay to distinguish single and double click).

robfaas commented 3 years ago

In your demo https://fancyapps.com/playground/vo change JS zoom: false to zoom: true and then click on a thumbnail. You first see the white container and only after a delay the photo will 'zoom in'. Same delay happens at closing the overlay.

fancyapps commented 3 years ago

No, there is no delay. Maybe you think there is delay because you do not see start of the animation, because it is also changing opacity (because ratio of thumbnail and full image do not match).

robfaas commented 3 years ago

A short video (background-border to red so you can watch the delay better): https://www.anothersite.nl/fancyapps/fancyapps-border.mp4

robfaas commented 3 years ago

I did not mean a delay between click and animation, but a delay between (dis)appearance of background/border and (dis)appearance of the full image. If you watch the video in my previous comment, you will see this delay. In this case especially long when the full image is being closed.

fancyapps commented 3 years ago

That is why that demo has disabled zoom, so you do not see that quirk :)

Long story short - I have spend years trying to find perfect solution to this problem and I have not yet found. It is currently not possible due to limitations of the HTML and CSS specification and CPU/GPU capabilities of the desktop/mobile devices. It is so frustrating that mobile devices can perfectly run 3D games, but can not smoothly resize single image with shadow. There are solutions, but they come with trade-offs.

robfaas commented 3 years ago

Ah! That explains it all. Frustrating indeed! So it will be no borders or borders-without-zoom.

fancyapps commented 1 year ago

Hi,

If anyone wants to add a border to an image, I figured out a way, see this demo - https://jsfiddle.net/5mt1Lnez/

Fancybox.bind('[data-fancybox="gallery"]', {
  on: {
    reveal: (_fancybox, slide) => {
      const doubleBorder = 10 * 2;

      slide.contentEl.insertAdjacentHTML(
        "beforeend",
        `<div class="custom-fancybox-bg"></div>`
      );

      slide.customBG = slide.el.querySelector(".custom-fancybox-bg");

      slide.panzoom.on("afterTransform", (panzoom) => {
        const bgScale =
              (panzoom.contentRect.width + doubleBorder) /
              ((panzoom.contentRect.fitWidth + doubleBorder) * panzoom.scale);

        slide.customBG.style.scale = bgScale;
      });
    }
  }
});
.custom-fancybox-bg {
  position: absolute;
  top: -10px;
  right: -10px;
  bottom: -10px;
  left: -10px;
  background: #fff;
  z-index: -1;

  opacity: 1;
  transition: opacity 0.2s ease;
}

.is-closing .custom-fancybox-bg {
  opacity: 0;
}

.fancybox__slide.has-image {
  padding: 40px 80px;
}