2017-08-08 56 views
1

我有嵌入網站,類同的YouTube應用程式的行爲上的視頻走在橫向模式切換到全屏模式,我想這樣做的JavaScript。我知道你不能使用全屏API不點擊的,因爲安全原因,一個按鈕,你不能強迫隱藏地址欄,但不存在任何解決方法嗎?如何隱藏瀏覽器地址欄在移動瀏覽器的方向變化?

我發現這個article並試圖開槍的方向變化下滾功能,但沒有奏效。我也改變了變量到一個更高的超時和較低的位置,也嘗試了另一種滾動功能:

$('html, body').animate({scrollTop: 100}, 100); 

仍然沒有效果...

這是代碼:

的Javascript取向的轉變功能:

updateOrientation: function() { 
    orientation = $(window).width()/$(window).height() < 1 ? 'portrait' : 'landscape'; 
    var device_width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0), 
     device_height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0), 
     new_width, 
     new_height; 
    if(orientation === 'landscape'){ 
     new_width = device_width; 
     new_height = device_height; 
     if($('#videoPlayer').length > 0 && $(window).scrollTop() < 50){ 
      $('html, body').animate({scrollTop: 100}, 100); //this should hide the address bar 
     } 
    }else{ 
     //code when switching back to portrait 
     ... 
    } 
    $('#videoPlayer').css({ 
     'width': new_width, 
     'height': new_height 
    }); 
} 

CSS:

@media screen and (orientation:landscape){ 
    article #videoPlayer{ 
     position: fixed; 
     top: 0; 
     left: 0; 
     width: 100vw; 
     height:100vh; 
    } 
    article #videoPlayer{ 
     background-color: #000; 
    } 
    video { 
     object-fit: contain; 
    } 
    body.player_initialized #sticky_navigation{ 
     display: none; 
    } 
} 

我檢查了幾個Stackoverflow條目,但沒有找到工作解決方案。任何人都知道這個答案或有暗示?

編輯: 的Scrolldown已解決辦法似乎爲移動Safari瀏覽器IOS但不適用於移動瀏覽器的工作。

回答

0

有一個屏幕方向API和全屏API,它可以攜手合作。它不是由Safari瀏覽器的支持,但在大多數的Android瀏覽器的工作原理:

if('orientation' in screen){ 
    window.screen.orientation.onchange = function() { 
      if (this.type.startsWith('landscape') && document.querySelector('#element').webkitRequestFullScreen) { 
      document.querySelector('#element').webkitRequestFullscreen(); 
      } else { 
      if(document.webkitCancelFullScreen){ 
       document.webkitExitFullscreen(); 
      } 
      } 
    } 
}