Skip to content

MudRipple: Show ripple effect based on click position (#157)#7637

Merged
henon merged 1 commit intoMudBlazor:devfrom
meenzen:feature/ripple-click-position
Oct 11, 2023
Merged

MudRipple: Show ripple effect based on click position (#157)#7637
henon merged 1 commit intoMudBlazor:devfrom
meenzen:feature/ripple-click-position

Conversation

@meenzen
Copy link
Contributor

@meenzen meenzen commented Oct 11, 2023

Description

This solution uses JavaScript to calculate an offset based on the click position. The offset is then applied to the ripple pseudo-element using css variables.

I've tried to make the ripple look the same as before. Because I had to double the size of the pseudo-element transform: scale(10,10) -> transform: scale(20,20) a minor visual difference may be noticeable. This could possibly be mitigated by calculating a scaling factor based on the distance between the click position and the center of the clicked element:

/* --mud-ripple-scale would need to be calculated in js */
transform: scale(calc(10 * var(--mud-ripple-scale)), calc(10 * var(--mud-ripple-scale)));

I'm not sure if the added complexity is worth it but I'd be happy to implement that as well if wanted.

Note: This does not have the same issue as the reverted ripple.js implementation, the ripple "stays with the button when it moves", see: #157 (comment)

resolves #157

How Has This Been Tested?

visually

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Before

before.mp4

After

after.mp4

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

This solution uses JavaScript to calculate an offset based on the click position. The offset is then applied to the ripple pseudo-element using css variables.
@github-actions github-actions bot added enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library PR: needs review labels Oct 11, 2023
@henon
Copy link
Contributor

henon commented Oct 11, 2023

Ohhh, finally, I love it! Thanks a lot!

@henon henon merged commit 6695e92 into MudBlazor:dev Oct 11, 2023
@henon
Copy link
Contributor

henon commented Oct 11, 2023

Btw, is this still on mouse up, which has always been wrong in my eyes?

@meenzen meenzen deleted the feature/ripple-click-position branch October 11, 2023 19:21
@meenzen
Copy link
Contributor Author

meenzen commented Oct 11, 2023

Yes, it's still triggered after the click. That's a limitation of the way the :active css selector is being used.

Disclaimer: I don't fully understand how this works.

I think the :active state (when the button is being pressed) is used to "prime" the animation. Only when the button is no longer considered active can the animation begin.

@SasTaro
Copy link

SasTaro commented Oct 11, 2023

It looks so much better now, thanks!

ilovepilav pushed a commit to ilovepilav/MudBlazor that referenced this pull request Nov 25, 2023
…MudBlazor#7637)

This solution uses JavaScript to calculate an offset based on the click position. The offset is then applied to the ripple pseudo-element using css variables.
@Flaflo
Copy link
Contributor

Flaflo commented Dec 6, 2023

I can't believe after all these years we finally have a ripple on mouse pos, I know I am late, but thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ripple effect on mouse position

4 participants