I have a small sample app here: http://codepen.io/DouglasGlover/full/OPpMaV/
This is a mobile-only experience (though it technically functions on desktop as well). Only concerned about mobile here.
The intended behavior is that a user touches their phone, and holds their finger down on the phone (anywhere on the screen). As they do this, the counter goes up. When they let their finger come off the phone, it stops the counter.
There is a use case where a user may (perhaps accidentally) rotate their phone just enough that the site's orientation switches. Currently, if that happens, the counter continues to count infinitely upwards. Subsequent touches initiate a second touch event, which makes it go faster (I can deal with that, fixing the initial issue should fix this).
So my problem seems to be that upon switching orientation, the touch event "dies". So "touchstart" fires initially, and I'm waiting for a "touchend" which never gets to fire.
Ideally, the user can touch the phone, then rotate it without consequence (and without breaking the experience).
Here's the prototype code as it stands now...
HTML:
<div class="touchspace"></div>
<div class="ls">
<div class="counter">0</div>
</div>
<div class="pt">
<div class="counter">0</div>
</div>
CSS:
body{ margin: 0; }
.ls, .pt{ display: block; width: 100vw; height: 100vh; }
.ls{ background: lightblue; }
.pt{ background: lightgreen; }
.counter{ display: block; position: relative; top: 10%; font-weight: bold; color: white; font-size: 20vw; width: 20%; margin: 0 auto; }
.touchspace{ display: block; position: absolute; bottom: 0; right: 0; background: transparent; z-index: 999; background: red; width: 500vw; height: 500vh; opacity: .5; }
@media all and (orientation:landscape){ .ls{ display: none; } }
@media all and (orientation:portrait){ .pt{ display: none; } }
JS:
var counter = 0,
interval;
$(".touchspace").bind("touchstart mousedown",function(){
interval = window.setInterval(function(){
counter++;
$(".counter").html(counter);
}, 1000);
});
$(".touchspace").bind("touchend mouseup",function(){
window.clearInterval(interval);
});