我一直有問題,我的網頁在iOS移動Safari瀏覽器 - 頁面凍結方向的變化。我的功能在$(window).resize();
上執行,這是Mobile Safari傾聽縱向/橫向的內容。jQuery返回false必要,但打破。每個代碼
在我的大腦受到傷害並拼命嘗試之後,我將return false;
添加到我的函數的.each();
部分,並且瞧!方向改變不再凍結!但是...
現在函數不會爲我定義的元素的.each();
運行。
我該如何讓所有元素都運行該功能,同時保持return false;
增加的行爲(防止Mobile Safari凍結)?
THANK YOU!
的JavaScript:
(function($){
$.respond = function(callback) {
$(document).ready(function() {
dimensions();
});
$(window).load(function() {
dimensions();
$('#load').fadeOut('fast', function() {
$('.z:first').fadeIn('slow');
$('#status').fadeIn('slow');
$('footer').fadeIn('slow');
});
});
$(window).resize(function() {
dimensions();
});
function dimensions() {
var i = $('.z');
i.each(function() {
var browserWidth = $(window).width();
var imgRatio = ($(this).width()/$(this).height());
var availableHeight = ($(document).height() - $('header').height() - $('#status').height() - $('footer').height() - 80);
var browserRatio = (browserWidth/availableHeight);
if (imgRatio >= 1) {
$(this).addClass('landscape');
}
if (browserRatio >=1.5) {
$('#container').css('min-height', '360px');
} else {
$('#container').css('min-height', '555px');
}
if (browserRatio >= imgRatio) {
/* landscape */
//$('body').css('background', 'blue');
$(this).height(availableHeight).width('auto').css('margin-top', '0');
} else {
/* portrait */
//$('body').css('background', 'green');
$(this).width(browserWidth - 40).height('auto').css('margin-top', (availableHeight - $(this).height())/2);
}
$(this).css('margin-left', (browserWidth - $(this).width())/2);
});
return false;
};
};
})(jQuery);
首先,你爲什麼濫用JavaScript,爲什麼你會忽略分號?是否發生了「不凍結」發生,因爲循環爆發了,因此,你應該尋找優化你的循環? – Shef
你能更具體一點嗎?在這段代碼中沒有任何語法錯誤...說Google開發控制檯 – technopeasant
'var imgRatio = $(this).width()/ $(this).height()var availableHeight =($(document).height( ) - $('header')。height() - $('#status')。height() - $('footer')。height() - 80)var browserRatio = browserWidth/availableHeight'添加分號。 – Shef