我有下面的代碼來捕獲瀏覽器調整大小事件。當調整窗口大小時,css(「position」)返回undefined
window.onresize = function(){
var style = $('#button-selection').position();
if(style == "relative"){
$("#button-section").css("position"," ");
}else if(style == "fixed"){
$("#button-section").css("position","relative");
}
};
window.onresize = function(){
var style = $('#button-selection').css('position');
if(style == "relative"){
$("#button-section").css("position"," ");
}else if(style == "fixed"){
$("#button-section").css("position","relative");
}
};
樣式返回undefined。當文檔準備就緒時,我正在運行它。我試着用窗口準備好,但結果是一樣的。上述兩個方法都返回undefined!
第二部分對我的作品如預期。看到這裏:http://jsfiddle.net/haZfH/ 也許你應該檢查什麼css('位置')實際輸出。也許問題出在CSS上。 – Chris 2013-04-11 08:04:55
我會檢查它!理論上第二種方法應該工作! – 2013-04-11 08:08:50