为什么准备/调整大小事件不能在iPad上运行?它们可以在电脑上工作,但不能在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 :(得分:1)
如果您尝试捕捉iPad的方向,则应使用:
window.onorientationchange = function(e) { /* your code */ };
而不是windows resize事件。
答案 1 :(得分:1)
请检查以下
$(window).resize(function() {
alert("Window size changed");
});
要访问高度和宽度,您可以使用
$(window).width();
$(window).height();
答案 2 :(得分: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.
}
}
}
希望这有帮助!
答案 3 :(得分:0)
尝试jQuery(document).ready(function(){ alert('booya!') })
;
如果收到提醒,请将代码放入该功能中。另请访问Chrome中的页面,并在开发者工具中调出内置控制台来检查Javascript错误。
答案 4 :(得分:0)
我找到了解决方案: 而不是jQuery(窗口).width()我使用了jQuery(document).width(),现在我的脚本可以在每个设备上运行:) 谢谢你的回答!
答案 5 :(得分:0)
现在可以使用,
我的代码不起作用,因为我使用了window.width(),它在iPad上不起作用,我将其更改为document.width,现在它可以正常工作。 :)