featherlight icon indicating copy to clipboard operation
featherlight copied to clipboard

Layered featherlight close animation

Open jcuenod opened this issue 10 years ago • 16 comments

When you open two featherlight boxes and click away/close the first there is a flicker as the background fades and then hides, suddenly showing the darker background of the box underneath.

jcuenod avatar Mar 26 '15 11:03 jcuenod

Yes, indeed. With the last-of-type css rule, only the frontmost lightbox darkens the screen. As this fades, the screen lights up. When the frontmost dialog gets removed, the last-of-type target changes and the screen darkens suddenly.

I'm not too sure what to do about it though.

marcandre avatar Mar 26 '15 13:03 marcandre

How about switching to first-of-type? Ahh, never mind - then the problem will be if the second featherbox is on top of a larger featherbox

jcuenod avatar Mar 26 '15 13:03 jcuenod

Mmm, that could work. Otherwise I guess I could check for nested case, and if it's nested, fade the content only. Your solution is the simplest though, let me check...

marcandre avatar Mar 26 '15 13:03 marcandre

So, first-of-type doesn't work with classes, but even if it would (or using the workaround with ~), the problem is that it needs to be the last one, coz we want to dim the content of the upper lightbox too... So back to my solution I guess.

marcandre avatar Mar 26 '15 13:03 marcandre

Maybe the solution is to have a few rules. I haven't run any test but I'm thinking something like:

:only-of-type {
  background: rgba(0, 0, 0, 0.8);
}

:last-of-type {
  background: rgba(0, 0, 0, 0.5);
}

::nth-last-of-type(2) {
  background: rgba(0, 0, 0, 0.3);
}

jcuenod avatar Mar 26 '15 13:03 jcuenod

Or else accept that the second window will dim the screen even further, i.e. just have background: rgba(0, 0, 0, 0.8) apply to all featherlights.

marcandre avatar Mar 26 '15 13:03 marcandre

Mmm, or use your "first-of-type" idea, but when opening/closing a nested featherlight, we fade-out/in the previous content box, that could look nice and no flicker I think...

marcandre avatar Mar 26 '15 13:03 marcandre

Yip I was thinking of something with css transitions as well so when the last-of-type box disappears css transitions kick in (I think they should).

jcuenod avatar Mar 26 '15 13:03 jcuenod

Just for reference, I was having further issues that turned out to be related to this ":last-of_type" selector https://github.com/iamceege/tooltipster/issues/369. The idea there was to put all the featherlights into one div. I think that's pretty useful. If you want me to open a new issue I will but I think perhaps it could help solve this problem:

<div class="feather-wrapper">
  <div class="featherlight">featherlight #1</div>
  <div class="featherlight">featherlight #2</div>
  <div class="featherlight">featherlight #3</div>
</div>

Now ".feather-wrapper" gets

background: rgba(0, 0, 0, 0.8);

But ".featherlight" gets

.featherlight {
  opacity: 0;
}
.featherlight:nth-last-of-type(2) {
  opacity: 0.3;
}
.featherlight:last-of-type {
  opacity: 1;
}

I'm not sure, but perhaps css transitions can animate the opacity variable for us when number 3 closes and the second featherlight ends up on top with the first now becoming visible.

Anyway nesting inside a div would be useful to me for tooltipster

jcuenod avatar Mar 28 '15 21:03 jcuenod

Just to note working towards solution here I've added

<div class="featherlight-holder"></div>

to the end of my <body> (which is modified and ends up with stuff after it anyway) but using

$.featherlight.defaults.root = $(".featherlight-holder")

has solved the bug with tooltipster. Next step the fading. This is useful functionality in my mind though - I would say worth making the default...?

jcuenod avatar Mar 29 '15 15:03 jcuenod

Okay, my solution (which I'm pretty happy with thus far) is:

.featherlight-holder {
  position:fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 1;
  background: rgba(0, 0, 0, 0.8);
}
.featherlight-holder:empty {
  display: none;
}
.featherlight {
  opacity: 0;
  -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  -ms-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;
}
.featherlight:nth-last-of-type(2) {
  opacity: 0.3;
}
.featherlight:last-of-type {
  opacity: 1;
  background: none;
}

jcuenod avatar Mar 30 '15 22:03 jcuenod

Will @jcuenod's solution be included in featherlight? @marcandre

negativefix avatar Nov 07 '15 19:11 negativefix

I like that solution. It probably could have been designed this way from the get go. I'm not too sure how to integrate it and stay compatible with people customizing their root option though. Also :empty is cute, but won't work in IE8. Easy to do in JS though.

marcandre avatar Nov 08 '15 03:11 marcandre

It's a long time since I looked at any of this code but how about making them mutually exclusive? That is, "If you want to customise your root, then figure out your own way of handling layers."

jcuenod avatar Nov 08 '15 14:11 jcuenod

@jcuenod You saved my life with your workaround. The default background is flickering when displaying an Google Map at each call of google.maps.event.trigger(map, 'resize') event. Thanks !

Nukium avatar Jun 29 '17 13:06 Nukium

@jcuenod You said "Next step the fading" but didn't post a solution 😢. Here is a simple workaround (hotfix).

In featherlight.js around line 314 next to :

self.$instance.fadeOut(self.closeSpeed,function(){ self.$instance.detach(); self.afterClose(event); deferred.resolve(); });

Add :

if($(self.root + ' > .' + self.namespace).size() == 1) { $(self.root).fadeOut(self.closeSpeed,function(){ $(self.root).css('display',''); }); }

It works with stacked boxes.

Nukium avatar Aug 31 '17 15:08 Nukium