2010-07-13 127 views
1

我期待單擊a.go,然後有一系列的div的所有類.box的動畫的到在輸入父.box的內保存的百分比jQuery元素動畫的孩子價值?

所以我看起來是這樣的:

<a class="go" href="#">go!</a> 

<div class="box><input type="hidden" value="50"/></div> 
<div class="box><input type="hidden" value="90"/></div> 
<div class="box><input type="hidden" value="20"/></div> 
<div class="box><input type="hidden" value="60"/></div> 


     $('a.go').click(
     function() { 
       $('.box').animate({ 
        "left": "50%" 
        }, 2000); 
      } 
     ); 

所以現在我可以動畫它們全部的50%,但我想他們對動畫的輸入值。我應該使用什麼?每()?

回答

0

是這樣的?

$('a.go').click(function() { 
    $('.box').each(function() { 
     $(this).animate({ left: $('input', this).val() + '%' }, 2000); 
    }); 
}); 
+0

就是這樣! – wesbos 2010-07-13 02:36:33