2013-01-22 55 views
1

$(window).resize不工作,我錯過了什麼?

所以我有一個350px寬度的垂直菜單,水平居中。鏈接打開顯示不同內容的iframe。顯示外部網站的iframe通過以下方式獲取寬度:$("#iframeweb").width($(document).width() - $('#menu').width()),以便填滿屏幕,並將菜單推向旁邊。

那部分工作,但它也需要改變窗口大小調整的寬度,但它什麼都不做......

代碼:

<div id="wrapper"> 
    <div id="outer"> 
    <div id="inner"> 
     <iframe name="iframeweb" id="iframeweb"></iframe> 
     <div id="menu"> 
       </div> 
     <iframe name="iframeA4" id="iframeA4"></iframe> 
    </div> 
    </div> 
    </div> 

<script type="text/javascript"> 
$(window).resize(function() { 
    $("#iframeweb").width($(document).width() - $('#menu').width()); 
}; 
</script> 

<script type="text/javascript"> 
$("#linkA4").click(function(){ 
    $("#iframeA4") 
     .hide('fast') 
     .animate({"width": "0px"}, 'fast') 
     .animate({"width": "210mm"}, 'fast') 
     .show('fast'); 
    $("#iframeweb").hide('fast'); 
}); 

$("#linkweb").click(function(){ 
    $("#iframeA4") 
     .animate({"width": "0px"}, 'fast') 
     .hide('fast'); 
    $("#iframeweb") 
     .hide('fast') 
     .width($(document).width() - $('#menu').width()) 
     .show('fast'); 
}); 
</script> 

回答

5

你有一個簡單的語法錯誤,關閉圓括號

$(window).resize(function() { 
    $("#iframeweb").width($(document).width() - $('#menu').width()); 
}); // <-- 
+0

那簡單嗎?!也許這只是休息的時間... – ThomasCS

+0

:-P控制檯/ Inspect元素是你最好的朋友,每當你做JS的時候,只要打開它就可以快速隔離語法錯誤,然後才能得到你最好的:) – Bryan

相關問題