Thursday, December 29, 2011

jQuery Mobile swiperight too sensitive

While adding functionalities that triggers when the jQuery Mobile swiperight event is fired, I met the same problem as ade_cd, where the swiperight event gets triggered even when I am scrolling a page. On examining the jQuery Mobile 1.0 source code, I realized that the jQuery Mobile team has taken his suggestion and made the previously hardcoded values into parameters.

The parameters should be changed after the jQuery Mobile script has loaded. Here is the _Layout.cshtml file I’m using for my ASP.NET MVC 3 project.

<!DOCTYPEhtml><html><head><metacharset="utf-8"/><metaname="viewport"content="initial-scale=1.0, width=device-width"/><title>@ViewBag.Title</title><linkhref="@Url.Content("~/Content/themes/red-blue/RedBlue.min.css")"rel="stylesheet"type="text/css"/><linkhref="@Url.Content("~/Content/themes/red-blue/jquery.mobile.structure-1.0.min.css")"rel="stylesheet"type="text/css"/><scriptsrc="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"type="text/javascript"></script><scriptsrc="@Url.Content("~/Scripts/jquery.mobile-1.0.min.js")"type="text/javascript"></script><scripttype="text/javascript"> $(function () { // huan086: Swipe right is way too sensitive on iPhone 4S and gets triggered even when scrolling vertically.// Set the horizontalDistanceThreshold to 50% of screen to make sure that it does not get triggered accidentally. $.event.special.swipe.horizontalDistanceThreshold = Math.min($(document).width() / 2, 160); }); </script></head><body>@RenderBody()
</body></html>