强制旋转横屏

<html>  
<head>  
<title>测试</title>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<style> 
	.yanshi1{
		position:absolute;
		top:0; 
		left:100%;
		transform:rotate(90deg);
		background: linear-gradient(to right, #030b18 -50%, #133a64 50%, #030b18 150%);
		transform-origin:0 0 0;
	}
	.yanshi2{
		position:absolute;
		top:0;  
		width: 100%;
		height: 100%;
		z-index: 120;
		background: linear-gradient(to right, #030b18 -50%, #133a64 50%, #030b18 150%); 
	}  
</style> 
</head> 
<body>   
    <div class="tjc yanshi2">
        <img  src="../ceshi.png" /> 
    </div> 
</body> 
<script src="../js/jquery-3.3.1.min.js"></script>  
<script>   
	$(window).resize(function() {
		xuanzhuan();
	});
	$(function(){  
		xuanzhuan();
	}); 
	function xuanzhuan(){
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		console.log('窗口宽度: ' + windowWidth + ', 窗口高度: ' + windowHeight);
		if(windowWidth<windowHeight){ 
			$('.tjc').css('height',$(window).width()); 
			$('.tjc').css('width',$(window).height()); 
			$(".tjc").removeClass("yanshi2");
            $(".tjc").addClass("yanshi1");
		}else{ 
			$('.tjc').css('height',$(window).height()); 
			$('.tjc').css('width',$(window).width()); 
			$(".tjc").removeClass("yanshi1");
            $(".tjc").addClass("yanshi2");
		} 
	}
</script>
</html> 

屏幕旋转度数 js方法

function hengshuping(){  
        var lsheight=$(document).height();
        var lswidth=$(document).width();  
        if(window.orientation==0){
            //竖屏
            $('.main').css('height',lsheight); 
            $('.main').css('width',lswidth); 
            $(".main").removeClass("yanshi2");
            $(".main").addClass("yanshi1");
        }else if(window.orientation==90){
            //横屏  
            $('.main').css('height',lswidth); 
            $('.main').css('width',lsheight);  
            $(".main").removeClass("yanshi1");
            $(".main").addClass("yanshi2");
        }
    } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值