[英]Javascript or jquery code for screen orientation
我需要Javascript或Jquery来检测屏幕方向,然后为每个方向加载不同的HTML和CSS。
我认为这是我从不同示例中组合而成的好代码,但是我不知道完成它所需的代码。
$(window).on("orientationchange",function(){
if(window.orientation == 0) // Portrait
{
jquery code here to load some external HTML AND CSS
}
else // Landscape
{
jquery code here to load some external HTML AND CSS
}
});
这看起来是否正确,完成此操作所需的代码是什么样的? 任何帮助都是极好的。
与其使用JS检测方向,然后重新粉刷显示器,为什么不只对布局使用CSS媒体查询/响应式设计呢?
我认为使用jQuery Mobile可以实现
$(document).on("pagecreate",function(event){
$(window).on("orientationchange",function(){
if(window.orientation == 0)// Portrait
{
//....................
}
else
{
//...............
}
});
});
或简单,必须与$(window).width()比较
写下面的JS代码
screen.addEventListener("orientationchange", function () {
console.log("The orientation of the screen is: " + screen.orientation);
});
听屏幕方向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.