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

Click event might need two taps on mobile browsers #14

Open
jjozsi opened this issue Dec 9, 2019 · 5 comments
Open

Click event might need two taps on mobile browsers #14

jjozsi opened this issue Dec 9, 2019 · 5 comments

Comments

@jjozsi
Copy link

jjozsi commented Dec 9, 2019

I heavily modified the button markup and due to :hover styles the first tap on mobile did not trigger the click event on the button.

I suggest modifying the following line
_.btnElement.click(function() {
to
_.btnElement.on('mousedown touchstart',function() {

That would make the click event fire under any circumstances.

@bartholomej
Copy link
Owner

Hi @jjozsi can you please provide any example where the event is not triggered? You can modify it in demo folder.

Your solution looks good BUT touchstart is fired too early, so button will never be marked as :active and ripple animation will not be triggered :(

@jjozsi
Copy link
Author

jjozsi commented Dec 12, 2019

Hi, first, the ripple effect doesn't work on desktop and iOS Safari but I've tested the demo on Chrome on Android and indeed it's there.
I implemented the code with a Bootstrap 4 button markup with most of the original styles removed and it only worked for the second tap on iOS Safari, but again BS has it's only default :hover styles.
Button markup:

<button class="material-scrolltop btn btn-light btn-lg" type="button"><i class="fas fa-chevron-up"></i></button>

Remaining styles:

.material-scrolltop {
    position: fixed;
    max-width: 0;
    max-height: 0;
    padding: 0;
    border-width: 0;
    bottom: $mst-gutter;
    right: $mst-gutter;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .5);
    cursor: hand;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1);
    overflow: hidden;
    i {
        margin-right: 0;
    }

    &.reveal {
        max-width: 4rem;
        max-height: 4rem;
        padding: $mst-padding;
        border-width: $border-width;
    }
}

@bartholomej
Copy link
Owner

What do you think about this update? https://github.com/bartholomej/material-scrolltop/tree/fix/mobile-click (Demo is also updated)

As you can see, there is a hack with :focus to keep animation working :)
0f3cc02

@jjozsi
Copy link
Author

jjozsi commented Dec 12, 2019

Awesome, thanks :)

@AMBIENTE1
Copy link

Hi there,
Unfortunately, if the page also have other buttons ( https://slovacdomu.cz ), then those buttons need two taps on IOS mobile browsers :( Tested on Iphone 7,8,11
Is there any solution?

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

No branches or pull requests

3 participants