I did it by adding swipeleft
and swiperight
event handlers to my datepicker container:
$("#datepicker").on("swipeleft", function(){
$("#datepicker table").first().animate({
marginLeft: "-100%"
},{
duration: "fast",
complete: function () {
$.datepicker._adjustDate("#datepicker", +1, "M" );
}
});
});
$("#datepicker").on("swiperight", function(){
$("#datepicker table").first().animate({
marginLeft: "100%"
},{
duration: "fast",
complete: function () {
$.datepicker._adjustDate("#datepicker", -1, "M" );
}
});
});
Both events are documented here: swipeleft and here: swiperight.
In addition, i just used this answer from SO How to disable text selection using jQuery? to avoid text selection inside my datepicker calendar (credits: Damien):
$(".ui-datepicker").attr('unselectable','on')
.css({'-moz-user-select':'-moz-none',
'-moz-user-select':'none',
'-o-user-select':'none',
'-khtml-user-select':'none',
'-webkit-user-select':'none',
'-ms-user-select':'none',
'user-select':'none'
}).bind('selectstart', function(){ return false; });
As you don't specify why the answer mentioned by you hasn't worked in your case, feel free to check my Plunker demo also in a real mobile device and let me know if this works now for you.
EDIT:
I made a small change to avoid a nasty drag side effect when a datepicker button is selected:
<div id="datepicker" ondragstart="return false;"></div>
Now it works nice and smoothly!
Credits: SyntaxError from this answer: Disable Drag and Drop on HTML elements?