css3完美解决手机横竖屏判断,让用户看邀请函更爽
2014-12-24 11:55
363 查看
html:
<div id="cover1"></div>
<p id="cover1w">亲,请竖屏观看本屏内容,谢谢^_^</p>
css:
/* 判断手机横竖屏 */
@media screen and (orientation:portrait) {
/* css[竖向定义样式] */
#cover1{display: none;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: none;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
@media screen and (orientation:landscape) {
/* css[横向定义样式] */
#cover1{display: block;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: block;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
/* PC客户端或大屏幕设备: 1280px 至更大 */
@media only screen and (min-width: 1280px) {
#cover1{display: none;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: none;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
其他参考解决方案:
当用户旋转屏幕的时候,会进入到你的监听方法中,然后通过window.orientation来获取当前屏幕的状态:
0 - 竖屏
90 - 逆时针旋转横屏
-90 - 顺时针旋转横屏
180 - 竖屏,上下颠倒
如果你不希望用户使用横屏方式查看你的网页,你可以在设备旋转时间监听里面对body使用CSS3里面的transition中的旋转来保持页面竖向。
移动设备上的页面,当屏幕旋转的时候会有一个orientationchange事件。你可以给body元素增加此事件的监听:
<body onorientationchange="updateOrientation();">
js解决方案
今天这里我们分享一个jQuery的代码,能够有效帮助大家判断横屏或者竖屏。注意这里调用了jQuery的方法,所以你需要引用jQuery类库。function orient() {
alert('gete');
if (window.orientation == 0 || window.orientation == 180) {
$("body").attr("class", "portrait");
orientation = 'portrait';
return false;
}
else if (window.orientation == 90 || window.orientation == -90) {
$("body").attr("class", "landscape");
orientation = 'landscape';
return false;
}
}
$(function(){
orient();
});
$(window).bind( 'orientationchange', function(e){
orient();
});
<div id="cover1"></div>
<p id="cover1w">亲,请竖屏观看本屏内容,谢谢^_^</p>
css:
/* 判断手机横竖屏 */
@media screen and (orientation:portrait) {
/* css[竖向定义样式] */
#cover1{display: none;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: none;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
@media screen and (orientation:landscape) {
/* css[横向定义样式] */
#cover1{display: block;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: block;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
/* PC客户端或大屏幕设备: 1280px 至更大 */
@media only screen and (min-width: 1280px) {
#cover1{display: none;width: 100%;height: 100%;background-color: #000;opacity:1;position: absolute;z-index: 9999;top: 0px;left: 0px;}
#cover1w{display: none;width: 70%;height: 40px;position: absolute;z-index: 10000;top: 50%;left: 15%;margin-top: -20px;font-size: 18px;color: #fff;font-weight: bolder;text-align: center;}
}
其他参考解决方案:
当用户旋转屏幕的时候,会进入到你的监听方法中,然后通过window.orientation来获取当前屏幕的状态:
0 - 竖屏
90 - 逆时针旋转横屏
-90 - 顺时针旋转横屏
180 - 竖屏,上下颠倒
如果你不希望用户使用横屏方式查看你的网页,你可以在设备旋转时间监听里面对body使用CSS3里面的transition中的旋转来保持页面竖向。
移动设备上的页面,当屏幕旋转的时候会有一个orientationchange事件。你可以给body元素增加此事件的监听:
<body onorientationchange="updateOrientation();">
js解决方案
今天这里我们分享一个jQuery的代码,能够有效帮助大家判断横屏或者竖屏。注意这里调用了jQuery的方法,所以你需要引用jQuery类库。function orient() {
alert('gete');
if (window.orientation == 0 || window.orientation == 180) {
$("body").attr("class", "portrait");
orientation = 'portrait';
return false;
}
else if (window.orientation == 90 || window.orientation == -90) {
$("body").attr("class", "landscape");
orientation = 'landscape';
return false;
}
}
$(function(){
orient();
});
$(window).bind( 'orientationchange', function(e){
orient();
});
相关文章推荐
- css3完美解决手机横竖屏判断
- 完美解决在Vista下国产手机IC模块MT6227的驱动
- Google Voice接收短信转发到手机的完美解决方法
- 2012-6-28 Android判断用户是平板还是手机的方法
- C#判断用户是手机访问还是PC访问
- 黄聪:用php判断当前用户访问网站是否为手机登录
- 在ASP.NET中怎么用SESSION判断用户是否登录? 以及Session登陆后丢失的解决办法
- PHP检测及判断手机登录用户是安卓或爱疯(iPhone)客户端
- php判断wap客户端(手机用户)
- Android判断用户是平板还是手机的方法
- 完美解决三星i9100(9250)手机基带未知、IEMI丢失问题
- Php判断用户通过手机访问wap还是电脑直接访问
- javascript判断iphone/android手机横竖屏模式
- 关于手机的完美ROOT和一些问题的解决
- Android判断用户是平板还是手机的方法
- php如何判断用户通过手机wap访问还是电脑直接访问
- JS判断用户是否有权限进入当前页面,没有直接关闭(解决IE7以上版本提示问题)
- php如何判断用户通过手机wap访问还是电脑直接访问
- 完美解决Javascript函数类型的判断
- 判断用户是通过手机还是电脑访问浏览器