How to properly apply dynamic inline styles to fancybox gallery images #563
-
I have a question, what is the best way to pass user created css variables to images in the fancybox carousel gallery? I have a Wordpress site that gives users/builders the ability to apply brightness, saturation, and contrast filters to images in a gallery block. When they choose to do this, it creates a CSS variable within the gallery element that is referenced in the gallery's SCSS file. Right now, in my fancybox.js file, I'm:
So far this is working, but not quite how I'd like it to. Currently, when you click the image and the carousel loads, the image appears briefly with no inline filter before adding it to the element. I'm sure this is just an order of operations issue, but after going through the documentation I didn't find anything that seemed to help with this problem. If this is not the way to go about it, I'd be happy to try something different. HTML:
Fancybox.js code:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
Hi, You use Fancybox.bind('[data-fancybox="gallery"]', {
on: {
"reveal": (fancybox, slide) => {
slide.imageEl.style.filter = 'brightness(1.75)';
},
},
}); |
Beta Was this translation helpful? Give feedback.
OK, thanks for the demo, now I understand the confusion. You see, to get better zoom in/out animation performance, the trick is to animate the thumbnail image and then switch to the actual image. That's why you see the delay. The simplest solution would be to apply a CSS filter to the wrapper element - https://jsfiddle.net/3otdsxwc/