[英]Preventing user viewing site in landscape on mobile phone
當用戶將手機置於橫向時,我想將網站“旋轉” 90度,以阻止他們盡可能多地在手機上使用橫向。 這可能在javascript中(我將在<head>
部分中運行)嗎?
謝謝
非jQuery方式。 除非確實需要,否則請勿將頁面重量增加90kb!
window.addEventListener('resize', function(){
if (window.innerHeight < window.innerWidth){
document.body.style.transform = "rotate(90deg)";
document.body.style.webkitTransform = "rotate(90deg)";
document.body.style.mozTransform = "rotate(90deg)";
}
});
另外,請注意這一點的用戶體驗。 除非他們期望,否則它可能會嚴重惹惱您的用戶。 絕對必要嗎?
$(window).resize(function(){
if($(this).height() < $(this).width()){
$("body").css("transform","rotate(90deg)");
}
});
DOC: https : //api.jquery.com/resize/
並且不要忘記添加jquery庫。
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
編輯:
如果您只使用javascript:
window.onresize = function(e) {
var w = this.innerWidth;
var h = this.innerHeight;
if(h < w){
document.getElementsByTagName("body")[0].style.transform = "rotate(90deg)";
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.