I'm trying to make a button, so when the user clicks on it, it changes its style while the mouse button is held down. I also want him to change his style in the same way if he is affected in a mobile browser. Apparently, the obvious thing for me was to use CSS: an active pseudo-class, but that didn't work. I tried: to concentrate, and that didn't work either. I tried: hover over the mouse and it seems to have worked, but it retained the style after I removed my finger from the button. All these observations were on the iPhone 4 and Droid 2.
Is there a way to reproduce the effect on mobile browsers (iPhone, iPad, Android and, hopefully, others)? So far I am doing something like this:
<style type="text/css"> #testButton { background: #dddddd; } #testButton:active, #testButton.active { background: #aaaaaa; } </style> ... <button type="button" id="testButton">test</button> ... <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.1.min.js'></script> <script type='text/javascript'> $("*").live("touchstart", function() { $(this).addClass("active"); }).live("touchend", function() { $(this).removeClass("active"); }); </script>
The active pseudo-class is for desktop browsers, and the active class is for touch-based browsers.
I am wondering if there is an easier way to do this without involving Javascript.
javascript jquery html css mobile
Elias Zamaria May 19 '11 at 18:36 2011-05-19 18:36
source share