2015-05-22 92 views
1

你好,我想做一個可擴展的div當我點擊一個按鈕: 和我想做的步驟動畫,第一步是點擊按鈕,第二個div寬度展開,第3步div高度展開以獲取完整頁面。 和文本里面的div必須改變像隱藏第一個文本,並顯示第二個步驟完成時 任何人都有一個想法如何做到這一點? 還有就是我想要做的步驟的草圖: http://img15.hostingpics.net/pics/719800Sanstitre1.jpgexpand div onClick

回答

2

需要jQuery animate

$('.blue').click(function(){ 
    //expand red div width to 200px 
    $('.red').animate({width: "200px"}, 500); 
    setTimeout(function(){ 
     //after 500 milliseconds expand height to 800px 
     $('.red').animate({height:"800px"}, 500); 
    },500); 
    setTimeout(function(){ 
     //after 1000 milliseconds show textarea (or textbox, span, etc) 
     $('.red').find('input[type="textarea"]').show();  
    },1000); 
}); 
+0

謝謝你的工作,但問題是,DIV高度會下降只有像高度不要讓之間的平等擴大上下,其僅擴大800像素的底部 – Tiaw

+0

是的,我想你會('。'red')。animate({marginTop:「-350px」,height:「800px」},500);' – stackoverfloweth

+0

是的,謝謝;-) – Tiaw

2

這可以用CSS真的很容易做到。 This video解釋得非常好。該視頻中有很多其他巧妙的技巧,但我將其與她解釋燈箱的部分聯繫起來。

.container { 
 
    padding: 100px; 
 
} 
 
.red, 
 
.blue { 
 
    width: 20px; 
 
    height: 20px; 
 
    float: left; 
 
    background-color: blue; 
 
} 
 
.red { 
 
    background-color: red; 
 
    font-size: 0; 
 
    color: white; 
 
    width: 50px; 
 
    transition: 1s height, 1s margin, 1s font-size, 1s 1s width; 
 
} 
 
.blue:focus ~ .red { 
 
    height: 100px; 
 
    width: 150px; 
 
    font-size: inherit; 
 
    margin-top: -40px; 
 
    transition: 1s width, 1s 1s height, 1s 1s margin, 1s 1s font-size; 
 
} 
 
.red .hint { 
 
    font-size: 14px; 
 
    padding: 4px; 
 
    transition: 1s 1s font-size; 
 
} 
 
.blue:focus ~ .red .hint { 
 
    font-size: 0; 
 
    transition: 1s font-size; 
 
}
<div class="container"> 
 
    <div class="blue" tabindex="-1"></div> 
 
    <div class="red"><span class="hint">text1</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt</div> 
 
</div>

+1

處做了一個保證金頂端啊!使用':focus'是我不會發生的事情,感謝分享! – Serlite

+0

也許可以在':checked'上使用'checkbox',這樣你可以通過點擊切換。 – redbmk

1
$(window).load(function(){ 
    $(".blue").click(function(){ 
     $(".red").animate({width:'400px'},1000).animate({height:'400px',top:'150px'},1000).text("qwqwqwq"); 
    }) 
}) 

`的.blue { 寬度:100像素; height:100px; background-color:blue;

} 
.red{ 
    width:200px; 
    height:100px; 
    background-color: red; 
    left:100px; 
    } 
div{ 
    display: inline-block; 
    margin:0; 
    padding: 0; 
    position: absolute; 
    top:300px; 

    }`