2012-11-16 17 views
0

在響應模板中,我有一些jquery代碼來按比例計算屏幕大小的圖像高度。它適用於所有瀏覽器,但在Iphone/Ipad上使用時,如果從縱向改變橫向,圖像不會調整大小,這裏是代碼,希望有人能幫助我! 由於jquery在響應模板中調整圖像不工作Iphone

//對於身體大小調整(文檔)$。就緒(函數(){ VAR bodywidth = $(文件).WIDTH(); VAR ratioheight =(bodywidth/3.582); $( 「#gallery」)。height(ratio);}); //對於身體

調整活性$(窗口).resize(函數(){ VAR bodywidth = $(文件).WIDTH(); VAR ratioheight =(bodywidth/3.582); $(「#廊「).height(ratioheight);});

回答

0

你使用的是jQuery手機嗎?如果是的話有一個事件來檢測方向變化稱爲orientationchange

或者從Detect viewport orientation, if orientation is Portrait display alert message advising user of instructions

window.addEventListener("orientationchange", function() { 
    // Announce the new orientation number 
    alert(window.orientation); 
}, false); 

採取有效的代碼應該是這樣的

$(window).bind('orientationchange resize', function(event){ 
     if(event.orientation) { 
      if(event.orientation == 'portrait') { 
      // do something 
       } else if (event.orientation == 'landscape') { 
         // do something else 
         } 
      } else { 
        // optional... PC-version javascript for example 
        } 

     }); 
+0

感謝穆罕默德,有趣的解決方案,但現在看來,這does not與var bodywidth = $(document).width(); var ratioheight =(bodywidth/3.582);你有任何想法如何保持Iphone/iPad的jQuery功能? – user1818326

+0

仍然有問題從縱向更改爲橫向,圖像不會調整大小以適應窗口的寬度,我可以幫助找出正確的解決方案嗎?謝謝 – user1818326

+0

你可以把它放在URL的某個地方,以便我可以在我的手機上測試 –

相關問題