css3完美解决手机横竖屏判断,让用户看邀请函更爽_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了css3完美解决手机横竖屏判断,让用户看邀请函更爽_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2342字,纯文字阅读大概需要4分钟。
内容图文
![css3完美解决手机横竖屏判断,让用户看邀请函更爽_html/css_WEB-ITnose](/upload/InfoBanner/zyjiaocheng/400/ce55bff27f604553a567cda45edcc9ad.jpg)
亲,请竖屏观看本屏内容,谢谢^_^
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元素增加此事件的监听:
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完美解决手机横竖屏判断,让用户看邀请函更爽_html/css_WEB-ITnose全部内容,希望文章能够帮你解决css3完美解决手机横竖屏判断,让用户看邀请函更爽_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。