2012-07-18 31 views
0

iPhone上報告了顯示問題。我一個也沒有。我想知道是否有人有任何想法。iPhone上的高度不正確

在我的網站上。這個問題似乎是由網址欄造成的。在Android上,功能$(window).height()返回(屏幕高度 - 網址欄)。在iOS上,它似乎沒有這樣做。

在我的網站上,我跳過了網頁欄。然後我將圖像全屏並居中。 (由於某些規範限制,我必須使用Javascript)

在Android中,圖像被調整大小到屏幕的可見區域。在iPhone上,它們被調整到可用的高度 - 網址欄。這會導致圖像太小而底部有間隙。至少這是我對這個問題的理解。

iPhone屏幕截圖。

with url bar
與地址欄

without the url bar
沒有地址欄

這是我用來調整圖像內容。

window.scrollTo(0, 1); 
function setImageSize() { 
    var windowWidth = $(window).width(); 
    var windowHeight = $(window).height(); 

    $('.photo-slide img').each(function() { 
     var width = $(this).attr('data-width'); 
     var height = $(this).attr('data-height'); 

     if (width > windowWidth) { 
      var ratio = windowWidth/width; 
      width = windowWidth; 
      height = height * ratio; 
     } 

     if (height > windowHeight) { 
      var ratio = windowHeight/height; 
      height = windowHeight; 
      width = width * ratio; 
     } 

     var marginTop = 0; 
     var marginLeft = 0; 

     if (windowHeight > height) { 
      marginTop = (windowHeight - height)/2; 
     } 
     if (windowWidth > width) { 
      marginLeft = (windowWidth - width)/2; 
     } 

     $(this).css({ 
      'margin-left':marginLeft+'px', 
      'margin-top':marginTop+'px', 
      'width':width+'px', 
      'height':height+'px' 
     }) 
    }) 
} 

有沒有人遇到過這個?我該如何解決這個問題,以便在url欄不可見時填充屏幕。

回答

0

如果您在setTimeout中將setImageSize()設置爲100毫秒等,那麼iPhone會給您正確的屏幕高度嗎?我記得這是前一個問題。或者不能使用window.navigator.userAgent.indexOf('iPhone')來檢查它是否是iPhone,然後將URL欄高度添加到圖像高度?

+0

歡迎來到SO。您應該添加建議/疑難解答作爲對問題的評論,除非您有明確的答案提供。有關更多信息,請參閱http://stackoverflow.com/about和http://stackoverflow.com/faq。 – Scott 2013-02-28 12:03:09

+0

好的謝謝,並不完全確定它是如何工作的,因爲我看不到評論按鈕或任何東西。我想我沒有足夠的代表直接評論這個問題。 – 2013-03-01 11:59:56