html5自动横屏的方法


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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM