2012-11-22 48 views
1

爲什麼iPad上的ready/resize事件不起作用?他們在電腦上工作,但不在iPad上工作。有人知道我做錯了什麼嗎?jQuery .ready/resize在iPad上不起作用

jQuery(document).on('ready', function() { 
    jQuery(window).on('resize', function() { 
     /* Tablet Portrait size to standard 960 (devices and browsers) */ 
     if (jQuery(window).width() < 960 && jQuery(window).width() > 768) { 
      //change the attributes from the div #home_content (first parameter: the attribute, what it needs to be) 
      jQuery('#home_content').attr('class','sixteen columns'); 
      jQuery('#slider').attr('class','sixteen columns'); 
     } 
     else{ 
      jQuery('#home_content').attr('class','nine columns'); 
      jQuery('#slider').attr('class','nine columns'); 
     } 

     /* Mobile Landscape Size to Tablet Portrait (devices and browsers) */ 
     if(jQuery(window).width() < 767 && jQuery(window).width() > 480) { 
      //code 
     } 
     else{ 

     } 

     /* Mobile Landscape Size to Tablet Portrait (devices and browsers) */ 
     if(jQuery(window).width() < 479) { 
      //code 
     } 
     else{ 

     } 
    }).trigger('resize'); // Trigger resize handlers.  
});//ready 
+0

你的意思是他們沒有工作,或沒有解僱?如果你把'alert('foo')'放在那裏,它會彈出嗎? – beeglebug

+0

在計算機上彈出,但不在iPad上 – Brampage

+1

您是否已將該提醒放入文檔或準備調整大小?他們兩個都不是射擊還是隻有一個? – beeglebug

回答

1

試試這個:

// Checks to see if the platform is strictly equal to iPad: 
if (navigator.platform === 'iPad') { 
    window.onorientationchange = function() { 

     var orientation = window.orientation; 

     // Look at the value of window.orientation: 
     if (orientation === 0) { 
      // iPad is in Portrait mode. 

     } else if (orientation === 90) { 
      // iPad is in Landscape mode. The screen is turned to the left. 

     } else if (orientation === -90) { 
      // iPad is in Landscape mode. The screen is turned to the right. 

     } else if (orientation === 180) { 
      // Upside down portrait. 

     } 
    } 
}​ 

希望這有助於!

1

如果你想捕捉的iPad的方向,你應該使用:

window.onorientationchange = function(e) { /* your code */ }; 

而非窗口大小調整事件。

+0

我應該如何在我的代碼中包含這樣的代碼?像這樣?:jQuery(window).onorientationchange()<960 etc ? – Brampage

0

嘗試jQuery(document).ready(function(){ alert('booya!') });

如果您收到警報,請將您的代碼放入該函數中。在Chrome瀏覽器中訪問該頁面,並通過在開發人員工具中打開內置控制檯來檢查Javascript錯誤。

1

請進行以下檢查

$(window).resize(function() { 

alert("Window size changed"); 

}); 

要訪問的高度和寬度,你可以使用

$(window).width(); 

$(window).height(); 
0

我找到了解決辦法: 代替的jQuery(窗口).WIDTH()我使用jQuery的(文件).WIDTH(),現在我的我的腳本工作有望在設備:)
謝謝您的回答!

0

它現在可以工作,

我的代碼沒有工作,因爲我沒有在iPad上工作的window.width(),我將其更改爲document.width,現在它可以工作。 :)

相關問題