Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not trasition opacity for .collapse element #41151

Open
3 tasks done
KES777 opened this issue Jan 14, 2025 · 0 comments · May be fixed by #41158
Open
3 tasks done

Can not trasition opacity for .collapse element #41151

KES777 opened this issue Jan 14, 2025 · 0 comments · May be fixed by #41158

Comments

@KES777
Copy link

KES777 commented Jan 14, 2025

Prerequisites

Describe the issue

I am aware of the problem that opacity is not animated when the element has display: none.
So I tried to work around the problem with this code:

      $( '#xxx' )
        .on('show.bs.collapse',  function ( e ) {
          e.target.style.opacity= 0;
          e.target.offsetHeight;      // Force reflow
          e.target.style.opacity= 1;
        })
        .on('shown.bs.collapse', function ( e ) { e.target.style.opacity= ''; })

When an element collaped it is defined at BS as the next:

.collapse:not(.show) {
  display: none;
}

Thus when the element has .collapse it is not displayed yet.

So when I checked BS source code:
image

the show.bs.collapse event is called (1) before it becomes displayed (2).

To my mind the show.bs.collapse should be called when the element is actually visible. But having this I see other issue:
a) element becomes visible with default properties
b) event is called
c) event handler sets required properties
d) element blinks for a short period of time
So this is not the solution.

The possible solution could be to fire events in the next order before.show.bs.collapse then show.bs.collapse and shown.bs.collapse events.

In this case I will be able to force reflow.

Reduced test cases

I do not have one.

What operating system(s) are you seeing the problem on?

Linux

What browser(s) are you seeing the problem on?

Firefox

What version of Bootstrap are you using?

v5.3

@Rishi-54 Rishi-54 linked a pull request Jan 17, 2025 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant