2012-09-04 108 views
0

我有兩個DIV垂直擴展的div

一個右邊,另一個在左邊

我正在尋找的是給我一個鏈接代碼,並通過點擊這個鏈接的div都將擴大至100%(意味着其中一人將下滑),並通過點擊一次他們將返回並排

我想這是一面:

<style> 
#container { 
    width:100%; 
    height:500px; 

} 
#left { 

    width:45%; 
    height:500px; 
    float: left; 
} 
#right { 

    width:45%; 
    height:500px; 
    float: left; 
} 
</style> 

<script type="text/javascript" src="scripts/jquery-1.8.0.min.js"></script> 


<div id="container"> 
     <div id="left"> 
     LEFT 
    </div> 

     <div id="right"> 
     RIGHT 
    </div> 
</div> 

<script> 
$('#container').click(function(){ 
     if (parseInt($('div#right').css('right'),10) < 0) { 
       // Bring right-column back onto display 
        $('div#right').animate({ 
         right:'0%' 
        }, 1000); 

        $('div#left').animate({ 
        width:'45%' 
        }, 600); 
       } else { 

     // Animate column off display. 
        $('div#right').animate({ 
         right:'-45%' 
        }, 600); 

        $('div#left').animate({ 
        width:'100%' 
        }, 1000); 
     } 

}); 
</script> 
+0

你看過jQuery的'toggle'功能嗎? http://api.jquery.com/toggle/ – Chase

+0

我添加了代碼 – roice81

回答

0

您可以使用jQuery的切換,爲您puspose 。

看看這個Example