Link to home
Start Free TrialLog in
Avatar of Steynsk
SteynskFlag for Netherlands

asked on

mousedown and mouseup for touch screen?

Hi Experts,

Yesterday Tom Beck helped me out with this script what does what should do on a regular PC.

But would it be possible to make this work on a touch screen?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='//code.jquery.com/jquery-2.1.3.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type='text/javascript'>
//<![CDATA[ 
$(function(){
$('#Clicker').mousedown(function () {
    var txt = '*';
    $('#output').text(txt);
    timeout = setInterval(function () {
        txt += '*';
        $('#output').text(txt);
    }, 100);

    return false;
});
$('#Clicker').mouseup(function () {
    clearInterval(timeout);
    $('#output').text('');
    return false;
});
$('#Clicker').mouseout(function () {
    clearInterval(timeout);
    $('#output').text('');
    return false;
});
});//]]>  
</script>
</head>
<body>
  <button id="Clicker">Push</button>
<p id="output"></p>
</body>
</html>

Open in new window

Avatar of Kimputer
Kimputer

The code works basically the same way, but you can't rely on the mousedown and mouseout feature (they're harder to trigger on either touchscreen or graphic tablet).
Rely mostly only on the mouseup event, put your important actions there.
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steynsk

ASKER

Dear Tom,

Again absolutely fabulous!

Thanks a lot,

Steynsk
You're welcome. Thanks for the points.