2012-11-22 54 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,现在它可以工作。 :)

相关问题