- 可能我们在写移动端项目的时候会有要求或者为了更好的体验会做<span style="font-size:18px;"><strong>横竖屏检测</strong></span>,以达到更好的用户体验。
- var utils = {
- debounce: function(func,delay){
- var timer = null;
- return function(){
- var context = this,
- args = arguments;
- clearTimeout(timer);
- timer = setTimeout(function(){
- func.apply(context,args);
- },delay);
- }
- }
- }
- var detectRes = document.getElementById('J_detectRes');
- var detectData = document.getElementById('J_detectData');
- function detectOrient() {
- var storage = localStorage;
- var data = storage.getItem('J-recordOrientX');
- var cw = document.documentElement.clientWidth;
- var _Width = 0,
- _Height = 0;
- if(!data) {
- sw = window.screen.width;
- sh = window.screen.height;
-
- _Width = sw < sh ? sw : sh;
- _Height = sw >= sh ? sw : sh;
- storage.setItem('J-recordOrientX',_Width + ',' + _Height);
- }else {
- var str = data.split(',');
- _Width = str[0];
- _Height = str[1];
- }
- if(cw == _Width) {
-
- return;
- }
- if(cw == _Height){
-
- return;
- }
- }
- window.onresize = utils.debounce(detectOrient,300);
- detectOrient();
- 详细介绍请参考原作者文章 <a target="_blank" href="http://jdc.jd.com/archives/3862" title="探讨判断横竖屏的最佳实现" style="font-family: "PingFang SC", Verdana, "Helvetica Neue", "Microsoft Yahei", "Hiragino Sans GB", "Microsoft Sans Serif", "WenQuanYi Micro Hei", sans-serif; font-size: 28px; text-decoration-line: none; color: rgb(255, 51, 68);">探讨判断横竖屏的最佳实现</a>
posted @
2017-11-04 09:58
五艺
阅读(
183)
评论()
收藏
举报