4
var slideWidth = $('#carousel #slideContainer .slide').width();
var slidePos = (($('ul#carousel_nav li').index(this)) * slideWidth);
slidePos = Math.abs(slidePos) * -1;

$('#carousel #slideContainer .slide .slideContents').stop();
$('#carousel #slideContainer').stop();

    $('#carousel #slideContainer .slide .slideContents').fadeOut( 500, function() 
    {
        $('#carousel #slideContainer').animate({ left: slidePos }, 1000, function() 
        {
            $('#carousel #slideContainer .slide .slideContents').fadeIn( 500 );
        });
    });

构建一个具有动画/回调链的 jQuery 滚动器。单击按钮时,div '#carousel #slideContainer .slide .slideContents应该淡出并且其容器div '#carousel #slideContainer .slide .slideContents移动 n 个像素(slidePos)

执行时,动画回调并不总是在前一个动画结束时触发,整个序列变得不连贯?!

4

1 回答 1

1

在我看来,pitaj 说的很管用

var slideWidth = $('#carousel #slideContainer .slide').width();
var slidePos = (($('ul#carousel_nav li').index(this)) * slideWidth);
slidePos = Math.abs(slidePos) * -1;

$('#carousel #slideContainer .slide .slideContents').stop(true);
$('#carousel #slideContainer').stop(true);

$('#carousel #slideContainer .slide .slideContents').fadeOut( 500, function() 
{
    $('#carousel #slideContainer').animate({ left: slidePos }, 1000, function() 
    {
        $('#carousel #slideContainer .slide .slideContents').fadeIn( 500 );
    });
});
于 2013-04-04T20:54:54.660 回答