I try to work on an interface on html5 for mobile.
i try to follow a mouvement, with touchstart/touchmove/touchend/touchcancel.
but when i try to follow a mouvement i allways quikly have au 'touchcancel' and no more touchmove then...
when i try this : http://miniapps.co.uk/code/touchcancel/
it work perfectly, i do not have any problem.
But i think the problem come from the mouvement of the web browser that interfering with my canvas.
Do you know can i fix this ?
// I try to explain more :
- Here is my test code : http://frys.free.fr/mNaissance/test.html
it's the "Jigsaw" puzzle code that i try to make working with a mobile.
I had a "log" div hunder the text.
And when i do "touchmove" on the grey canvas i have very fast a 'touchcancel' and no anymore 'touchmove'
Is it more clear ? sorry for my poor english !
Thanks for help
I believe I found out the reason for this - Android browser (as well as Chrome for Android 4.0+) believes you are trying to scroll, so it fires the touchcancel event. What you should do is
event.preventDefault();
on touchmove event you are capturing.
Related
I was trying to make something in Adobe Flash, Air for android. I simply made a square and converted it to an Symbol (called 'hello') and I entered this code.
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
hello.addEventListener(TouchEvent.TOUCH_TAP, tap);
function tap(event:TouchEvent):void
{
hello.x+=15;
}
but nothing happend. I even used CODE SNIPPERS, and also tested this on my phone(ALCATEL onetouch idol mini), and it also said that there are no errors.What have I done wrong?
You set everything correctly but forget only one important thing: check if the system supports touchevent.
if(Multitouch.supportsTouchEvent)
I've tried both techniques in this answer to get a "dragging touch highlight" across elements in my PhoneGap App (testing on Android).
Here's my JSFiddle of the touchmove approach
$("td").bind("touchmove", function(evt){
var touch = evt.originalEvent.touches[0]
highlightHoveredObject(touch.clientX, touch.clientY);
});
Here's my JSFiddle of the vmousemove approach
$("#main").bind("vmousemove", function(evt){
$('.catch').each(function(index) {
if ( div_overlap($(this), evt.pageX, evt.pageY) ) {
$('.catch').not('eq('+index+')').removeClass('green');
if (!$(this).hasClass('green')) {
$(this).addClass('green');
}
}
});
});
Both work perfectly when emulating the app from desktop browser. Both work when viewing the JSFiddles from my Android tablet browser. But in the installed app on the tablet, it doesn't work. Instead of an updating highlight as I drag across the elements, all I get is a highlight on the first-touched event. The same for both methods.
Any ideas what's going on?
A comment on this question has an intriguing suggestion that "If you are running on android you also need to cancel the touchmove event to get new ones while touching. Don't ask me why...". Does that ring a bell, and if so, how would I "cancel the touchmove event to get new ones" with either of these approaches?
Alternately, has anyone successfully done a "dragging highlight" effect on a PhoneGap app, and would you care to share your technique?
I searched for weeks for a slide plugin that would work on a Phonegap app using knockout, bootstrap and jQuery. Unfortunately, nothing was fitting my needs. So, I built a custom slider. It seems to be working (I'm currently testing it on Android 2.3.4 - I'm starting with the lowest version we plan to support), but it doesn't always respond. The touchstart event seems to be rather sensitive. Does anyone have any ideas on how I can make the user experience more consistent and reactive to the touchstart event? I have researched on this for a few days, and it seems others have similar issues, but nothing exactly like mine. And none of the issues seem to have a definitive answer. Does Phonegap have issues with touch events?
Here is my knockout function:
performSlide: function() {
$('#sliderDiv').on({ 'touchstart' : function() {
$('div.slideArrow').animate({
left: "+=200"
}, 1000, function() {
shell.navigate('home', 'slide');
});
}
});
}
I'm using the event binder on a div to call the function.
<div class="linkHeader" id="sliderDiv" data-bind="event: { touchstart: performSlide }">
I have also ensured that the z-index of my div is set higher than the other elements. The position attribute is also set to relative.
Any advice offered would be much appreciated. I would love if this performed a little better... ok, a lot better. :-)
I have not received an answer, but I ended up figuring out what I needed to change. First, I needed to detect my event and capture it in a variable. Then, I also changed the databinding and .on function to detect the touchmove instead of the touchstart. It is working much better now.
I have this scrollable list of elements that aren't responding to the 'click' event on Chrome for Android. However, 'touchstart' does work. The problem is, using 'touchstart' interferes with the swiping behavior of the list. Is there an alternative to 'click' I could use?
Doesn't work:
jQuery(document).on('click', '.items section', function(e) {
// code
});
Does:
jQuery(document).on('touchstart', '.items section', function(e) {
// code
});
You might need to let us see the code that you are using before anyone can be of much help.
But your problem might be that touch start is bind to what ever the user does so you may need to unbind it.
Without seeing the code its hard to diagnose the problem.
I have a small phonegap application with jquery mobile and backbone.
I'm trying to show popup to user by manually calling .popup() method.
Everything works fine on iOS but on android I got strange issue: popup is showing for few moments and than disappear.
Here the actual code:
var PostView = Backbone.View.extend({
events: {
'touchend .add-comment-button': 'addComment'
},
addComment: function() {
this.$(".comment-popup").popup('open', { history: false });
return false; // Stop bubbling.
}
});
I'm using history: false because this popup is actualy part of subpage.
The code looks very simple, I'm just can't understand why it can disappear, and why this happen only on android devices.
Thanks, and sorry for my bad english.
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
1 - Use the uncompressed jqm file. i.e jquery.mobile.1.2.0.js
2 - I was triggering the popup programatically using the 'tap' option - once changed to the 'click' option it worked.
$('.option').live('click', function() {
$('#popup-div').popup('open');
});
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
this code snippet may help you ->
$('#testBtn').on('tap',function(e){
console.log("button clicked");
e.preventDefault();
$('#testPOPUP').popup("open");
});
Please note i have used e.perventDefault().
I didn't feel like changing my .tap() events to the click event and I didn't have a case where I could use preventDefault()so I just added a timeout to the popup('open') line. My hoverdelay in jqm is set to 150 so I set this timeout to 600 just to be on the safe side. Works fine, doesn't feel sluggish for the user.
One way to 'fix' it is by setting data-history="false" on the popup div
See also this question
JQuery Mobile popup with history=false autocloses
I have the exact same problem when trying to use popup('open') on an android 2.3 device (both in native browser and in firefox) and it works just fine on browsers on other devices. I'm also using backbone event management to open my popup (used the tap event and no aditionnal options to popup).
What I did to 'correct' the problem is that I removed the backbone event management for this event and added a listener in the render function. In your case this would look something like this :
events: {
// 'touchend .add-comment-button': 'addComment'
},
render: function() {
$(this.el).html(this.template(this.model));
$(this.el).find('.add-comment-button').tap(function(el){
this.addComment(el);
return false;
}.bind(this));
}
I have no idea where the problem comes from (must be some incompatibility between backbone and jquery mobile) and why we only see it on android but for the moment with this workaround my app seems to work fine on any device.
Edit: oops, it turns out that in my case the problem was I was missing "return false;" in the function dealing with the event.
Now that I added it, it works correctly with the backbone event management.
Sadly that doesn't explain why you have the issue and why I was seeing it only on android.
In case it helps anyone, I had the same problem occurring with Bing Maps, with the Microsoft.Maps.Events.addHandler(pin, 'click', callback) method.
Not particularly nice, but instead I stored an ID in pushpin._id and did the following:
$("#page").on('vclick', function (event) {
if (event.target.parentElement.className === "MapPushpinBase") {
$("#stopPopup").popup('open');
}
});
One brute force option is to check whether popup was hidden and reopen it.
In a loop, because the exact time the popup becomes hidden seems to be varied.
var hidden = $('#' + id + '-popup') .hasClass ('ui-popup-hidden')
if (hidden) $('#' + id) .popup ('open')
A working example: http://jsfiddle.net/ArtemGr/hgbdv9s7/
Another option could be to bind to popupafterclose:
var reopener = function() {$('#' + id) .popup ('open')}
$('#' + id) .on ('popupafterclose', reopener)
$('#' + id) .popup ('open')
Like here: http://jsfiddle.net/ArtemGr/gmpczrdm/
But for some reason the popupafterclose binding fails to fire on iPhone 4 half of the time.