我試圖使我的網站上的動畫材料設計。正如你所看到的,當我按下按鈕時,它們中的每一個都會動畫,而不是隻動畫我按下的那個。編輯:我做了gif之後,我設法得到了一個流暢的動畫,但它們仍然是一個動作。 http://oi59.tinypic.com/29ek9wx.jpg這是我得到的動畫。 這裏是我的查詢代碼:Div的動畫作爲一個,而不是單獨的
$(document).ready(function() {
var toggleState = true;
$('.show').on("click", function() {
if(toggleState) {
$(this).find('svg').each(function(){
$(this).css({
transform: "rotate(180deg)"
});
});
$(document).find('.box').each(function(){
$(this).css({
height: "+=200"
},1000);
});
} else {
$(this).find('svg').each(function(){
$(this).animate({
transform: "rotate(+=180deg)",
});
});
$(document).find('.box').each(function(){
$(this).css({
height: "240" // this is the default height
},1000);
});
}
toggleState = !toggleState;
});
});
// .show is the container of the svg(the arrow). .box is the container of the whole thing
PS:我做管理.gif文件後得到一個平滑的動畫,唯一的問題是他們作爲一個。 PS2:不介意光標。
更多代碼。
<div class="fluid-layout">
<article class="box-wrapper">
<section class="box">
<div class="main-color" id="red">
</div>
<div class="show">
<svg class="svg" xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
<path d="M18 12l-9 9 2.12 2.12 6.88-6.88 6.88 6.88 2.12-2.12z"/>
<path d="M0 0h36v36h-36z" fill="none"/>
</svg>
</div>
</section
><section class="box">
<div class="main-color" id="pink">
</div>
<div class="show">
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
<path d="M18 12l-9 9 2.12 2.12 6.88-6.88 6.88 6.88 2.12-2.12z"/>
<path d="M0 0h36v36h-36z" fill="none"/>
</svg>
</div>
</section
><section class="box">
<div class="main-color" id="purple">
</div>
<div class="show">
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36">
<path d="M18 12l-9 9 2.12 2.12 6.88-6.88 6.88 6.88 2.12-2.12z"/>
<path d="M0 0h36v36h-36z" fill="none"/>
</svg>
</div>
</section
>
</article>
</div>
你可以把你的代碼放在jsfiddle中,這樣可以很容易地調試/提供反饋。 http://jsfiddle.net/ – Fermis 2014-11-21 21:22:32
http://jsfiddle.net/5dLyqsyu/2/ – 2014-11-21 21:32:10