html5自动横屏的方法

时间:2019-11-13 21:15:20   收藏:0   阅读:425

html5自动横屏的方法
<pre>
var evt = "onorientationchange" in window ? "orientationchange" : "resize";
 
 
 
window.addEventListener(evt, function() {
 
console.log(evt);
 
var width = document.documentElement.clientWidth;
 
var height = document.documentElement.clientHeight;
 
$print = $(‘#print‘);
 
if( width > height ){
 
 
 
$print.width(width);
 
$print.height(height);
 
$print.css(‘top‘, 0 );
 
$print.css(‘left‘, 0 );
 
$print.css(‘transform‘ , ‘none‘);
 
$print.css(‘transform-origin‘ , ‘50% 50%‘);
 
}
 
else{
 
$print.width(height);
 
$print.height(width);
 
$print.css(‘top‘, (height-width)/2 );
 
$print.css(‘left‘, 0-(height-width)/2 );
 
$print.css(‘transform‘ , ‘rotate(90deg)‘);
 
$print.css(‘transform-origin‘ , ‘50% 50%‘);
 
}
 
 
 
</pre>

原文:https://www.cnblogs.com/newmiracle/p/11853044.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!