2013-07-25 109 views
0

進出口尋找一種方法,使內容div擴張的iframe的點擊正確顯示iframe內容,代碼:的div標籤和iframe中

<div id="content"> 
    <div id='outerdiv'> 
    <iframe src="http://mywebsite.com" id='inneriframe' scrolling="no"></iframe> 
    </div> 
</div><!-- end of content --> 

CSS是

#content 
{ 
    width: 790px; 
    height:auto; 
    padding: 5px 55px 0; 
} 

#outerdiv 
{ 
    width:790px; 
    height:446px; 
    overflow:hidden; 
    position:relative; 
} 

#inneriframe 
{ 
    position:absolute; 
    top:-268px; 
    left:-230px; 
    width:1280px; 
    height:1198px; 
} 

任何建議,將不勝感激。

+0

爲什麼不使用寬度:100%;高度:100%iframe – Hushme

回答

0

首先,我們必須清理你的CSS代碼:

#iframe{ 
    position: absolute; 
    width: 100px; 
    height: 100px; 
} 

現在我們必須寫一些jQuery中:

var iframeDoc = $('#iframe').contents().get(0); 

var start = "big"; 
$(iframeDoc).bind('click', function(event) { 
    if(start == "big"){ 
     $("#iframe").animate({width:"100%", height:"100%"}, 1000); 
     return start = "small"; 
    } else if(start == "small") { 
     $("#iframe").animate({width:"100px",height:"100px"},1000); 
     return start = "big"; 
    } 
}); 

用途:

<iframe id="iframe" src=""></iframe> 

的jsfiddle:http://jsfiddle.net/YuWSy/