0

asmselectと同じ方法でリストアイテムをアニメーション化しようとしていますが、プラスマイナスではなく高さから2pxを減算し続けるようです

<script type="text/javascript">
$(document).ready(function() {

$('#name').change(function(){
    $('#name option:selected').each( function() {       


                /*$('.asmListItem').animate({
                    opacity: "show",
                    height: "show"
                }, 100, "swing", function() { 
                    $('.asmListItem').animate({
                        height: "+=2px"
                    }, 50, "swing", function() {
                        $('.asmListItem').animate({
                            height: "-=2px"
                        }, 25, "swing"); 
                    }); 
                });*/
                $('#select-to')
                  .append("<li class='asmListItem' value='"+$(this)
                  .val()+"'><span class='asmListItemLabel'>" + '<b>'+$('#subnam').val() + ' </b>' + $(this)
                  .text()+"</span><a href=# class='asmListItemRemove'>remove</a></li>");

        $(this).remove();
    });
});

 $('.asmListItemRemove').live('click', function() {
            $(this).closest('li').remove();

});

});

何か案は?

4

1 に答える 1

0

アニメートするたびに、li要素はどんどん小さくなっていくようです。

あなたのマークアップがどのように見えるかわからないので、ここでそれを再現しようとしました:

http://jsfiddle.net/ytYmT/

高さを2pxずつ増やしてから、1つのアニメーションが完了したときに2pxずつ減らす代わりに、元の高さの値を保存し、2ずつ増やしてから、元の高さに戻しました。

           $('.asmListItem').animate({
                opacity: 'show',
                height: 'show'
            }, 100, "swing", function() { 
                var originalHeight = $('.asmListItem').height();
                $('.asmListItem').animate({
                    height: originalHeight + 2 + "px"
                }, 50, "swing", function() {
                    $('.asmListItem').animate({
                        height: originalHeight + "px"
                    }, 25, "swing"); 
                }); 
            });
于 2012-02-21T14:31:15.923 に答える