我正在创建一个使用phonegap(cordova)框架的ios/android应用程序。我的UI代码在水平方向上有点欠缺。所以,我只想改变水平方向的外观,而不是垂直方向。有没有一个条件可以在index.html中应用,最好是在javascript/jquery中。提前谢谢。
发布于 2012-12-26 13:47:56
您可以为事件onOrientationChange()创建一个事件侦听器,您可以在其中更改应用于特定方向的css文件。
// create the link tag for the css file in your head section
<HEAD>
<LINK ID="OrientationSpecificCSSTag" REL="stylesheet" TYPE="text/css" HREF=""> // keep the href empty, will set later
.....
</HEAD>现在,在javascript文件或script标记中附加事件侦听器
// attach the onOrientationChange event listener in your script tag
window.addEventListener( 'onorientationchange', OnOrientationChange, false );实现OnOrientationChange函数,该函数根据方向实际更改css文件
function OnOrientationChange()
{
// case: if portrait
if( window.orientation == 0 || window.orientation == 270 )
{
document.getElementById('OrientationSpecificCSSTag').HREF = 'landscape.css';
}
else
{
document.getElementById('OrientationSpecificCSSTag').HREF = 'portrait.css';
}
}https://stackoverflow.com/questions/14036101
复制相似问题