Hbuilder android 监听横竖屏状态,进行放大缩小

    使用hbuilder做了一个app,有一个功能有一个放大缩小的按钮,如果是竖屏,点击按钮,图形变成全屏,且要隐藏掉状态栏,搜了一下可以使用js的方式监听横竖屏状态,hbuilder api也提供了设置横竖屏的方法,如下:

                //放大缩小按钮full_screen,2018年11月9日11:23:42
    	        $("#full_screen").click(function () {
            	console.log("放大缩小图形按钮");
            	 if (window.orientation === 180 || window.orientation === 0) { 
                      plus.screen.lockOrientation("landscape-primary"); // 把屏幕方向改变成横屏正方向
                 } 
	             if (window.orientation === 90 || window.orientation === -90 ){ 
	                plus.screen.lockOrientation("portrait-primary"); // 把屏幕方向改变成竖屏正方向
	             } 
            }); 

这是监听手机横竖屏,进行样式的设置,其中: 

                   // 设置应用全屏显示!
                  plus.navigator.setFullscreen(true);//可以设置设备全屏显示

//判断手机横竖屏状态:
			window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function() {
	            if (window.orientation === 180 || window.orientation === 0) { 
		          // 设置应用非全屏显示!
                  plus.navigator.setFullscreen(false);
		           console.log("竖屏了")
                  $("#mainCanvas").css("width", '98%');
                  $("#mainCanvas").css("height", '99%');
	            } 
	            if (window.orientation === 90 || window.orientation === -90 ){ 
	               // alert('横屏状态!');
	               console.log("横屏了");
	                // 设置应用全屏显示!
                  plus.navigator.setFullscreen(true);
                  
                  $("#mainCanvas").css("width", '98%');
                  $("#mainCanvas").css("height", '99%');
                  $("#mainCanvas").css("padding-top", '30px');
                  //$("#mainCanvas").css("margin-bottom", '25%');
	            }  
			}, false); 
			//移动端的浏览器一般都支持window.orientation这个参数,通过这个参数可以判断出手机是处在横屏还是竖屏状态。

css中也提供了,根据设备的横竖屏状态,可以设置不同的css样式,如下:

@media all and (orientation: portrait) {
	.account_layout,.kLineFooter_layout,.kline_top_outerlayout{
		display: block;
	}
	
}
@media all and (orientation: landscape) {
	.account_layout,.kLineFooter_layout,.kline_top_outerlayout{
		display: none;
	}
	
	.ui-page-footer-fixed{
		padding-bottom: 0em !important;
		padding-top: 13px !important;
	}
	
	.timeSpanTable{
		margin-top:40px;
		position:absolute;
        bottom:0px;
	}
	
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值