此代码必须在包含 jQuery Core 之后、包含 jQuery Mobile 之前运行。原因是要运行代码,jQuery 必须存在,但需要在 jQuery Mobile 初始化之前绑定此事件处理程序。
例如:
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
$(document).bind("mobileinit", function()
{
if (navigator.userAgent.indexOf("Android") != -1)
{
$.mobile.defaultPageTransition = 'none';
$.mobile.defaultDialogTransition = 'none';
}
});
</script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
文档:http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html http://jquerymobile.com/demos/1.1.0/docs/api/globalconfig.html
此外,UA 嗅探不是必需的,因为 jQuery Mobile 会测试设备的 CSS 3D 转换支持,并且仅在支持它们的设备上使用良好的转换。在 jQuery Mobile 1.1.0+ 中已为您完成此操作,但默认的后备过渡是fade
所以无论如何你都必须更改默认值。
定义非 3D 支持的后备过渡
默认情况下,除淡入淡出之外的所有过渡都需要 3D 变换支持。
缺乏 3D 支持的设备将退回到淡入淡出过渡,
无论指定的转换如何。我们这样做是为了主动
将 Android 2.x 等性能不佳的平台排除在高级之外
过渡并确保他们仍然拥有流畅的体验。注意
有Android 3.0等平台在技术上支持3D
变换,但动画性能仍然很差,所以这不会
保证每个浏览器 100% 无闪烁,但我们尽力
负责任地以此为目标。
不支持 3D 变换的浏览器的后备过渡
可以为每种转换类型进行配置,但默认情况下我们指定
“淡出”作为后备。例如,这将设置后备
滑出过渡到“无”的过渡:
$.mobile.transitionFallbacks.slideout = "none"
Source: http://jquerymobile.com/demos/1.1.0/docs/pages/page-transitions.html http://jquerymobile.com/demos/1.1.0/docs/pages/page-transitions.html
作为一般观察,我注意到你把if/then
声明在事件处理程序内,您也可以将其放在外部,这样如果它不是 Android 设备,则事件绑定/触发永远不会发生。
例如:
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
if (navigator.userAgent.indexOf("Android") != -1)
{
$(document).bind("mobileinit", function()
{
$.mobile.defaultPageTransition = 'none';
$.mobile.defaultDialogTransition = 'none';
});
}
</script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>