3

jQuery.animate()を使用して無限カルーセルを作成しています。.animate()以前は問題なく使用していました。ただし、今回はアニメーションが完成していません。

これは非常に単純なアニメーションでmargin-left、別の値に変化します。値が変化し、私にはそれが完了したように見えますが、関数は起動しません。

これが私のコードです:

<script type="text/javascript">
  $("#scrollLeft").click(function(){
      $("#scrollContent").animate(
        {'margin-left':'-714px'},
        {queue:false, duration:500},
        function(){
            alert("finishedLeft");
      });
  });
  $("#scrollRight").click(function(){
      $("#scrollContent").animate(
        {'margin-left':'-1190px'},
        {queue:false, duration:500},
        function(){
            alert("finishedRight");
      });
  });
</script>

問題の領域は、ページの下部にあるカルーセルです。を使い果たしていますjquery-1.7.1.min.js

私の主な質問は、イベントが完了したように見えても、何がこの関数の起動を妨げているのでしょうか?

4

1 に答える 1

6

構文に注意してください。

http://jsfiddle.net/n1ck/HBCn5/

$("#scrollLeft").click(function() {
    $("#scrollContent").animate({
        'margin-left': '-714px', // don't close out the parameters with parentheses yet ...
        queue: false,            // continue adding the queue option (if needed)
        duration: 500            // and the duration option (if needed) and close after
    }, function() {
        alert("finishedLeft");
    });
});
$("#scrollRight").click(function() {
    $("#scrollContent").animate({
        'margin-left': '-1190px', // same as above
        queue: false,
        duration: 500
    }, function() {
        alert("finishedRight");
    });
});​    ​
于 2012-05-31T01:14:37.133 に答える