Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap buttons get "stuck" down on mobile devices

Whenever I click a button with my mobile device (android) on a twitter boostrap button but button gets odd styling like the mouse is still over and doesn't release until I click another element. This is not the active class being applied to an element. This is what the button looks like before clicking

This is what the button looks like after clicking notice the shading and background

It's subtle but very annoying, especially when I try to apply styles to the button they dont show up until i click on a different element.

Try going to http://twitter.github.com/bootstrap/base-css.html#buttons on a mobile device and click a button you'll see what i mean

I tried triggering all sorts of events with jquery but nothing worked, this is a snippet i have at the END of my javascript

$(document).on('tapclick', '.btn', function() {
          $(this).blur(); 
          $(this).trigger('mouseup'); 


        });

and tried overriding css stylings on hover

.btn a:hover,.btn a:link,.btn a:visited,.btn a:active{
text-decoration: none !important;
cursor: default !important;
background-color: transparent !important;
background-image: none !important;
 }
like image 911
Brian Avatar asked Mar 09 '13 00:03

Brian


2 Answers

If you are just developing for mobile then you could simply override the hover css altogether, for example:

.btn:hover {
    background-color: inherit;
}
like image 199
Simon H Avatar answered Nov 03 '22 04:11

Simon H


I fixed this problem by adding a class to the button on the touchend event and then overriding the default bootstrap background position.

javascript:

$("button").on("touchstart", function(){ 
    $(this).removeClass("mobileHoverFix");
});
$("button").on("touchend", function(){ 
    $(this).addClass("mobileHoverFix");
});

css:

.mobileHoverFix:hover,
.mobileHoverFix.hover{
    background-position: 0 0px;
}
like image 37
Casey Avatar answered Nov 03 '22 03:11

Casey