0

ユーザーがページの最初のセクションをスクロールしたときにフェードインしたいヘッダーがあります。次のように不透明度 1 に変化する不透明度 0 の div を使用します。

$(window).scroll(function () {
           // If the scroll position is past the 1st section...
            if ($('body').scrollTop() > 500) {

                $('#ribbon').css('opacity', 1);

            } else {

                $('#ribbon').css('opacity', 0);
            }
    });

fadeIn()これは正常に機能しますが、またはを使用して不透明度をアニメーション化しようとするとanimate()、動作が停止し、div でフェードインしません。

4

1 に答える 1

1

LIVE DEMO

$(window).scroll(function () {

    var opacity = $(this).scrollTop() > 500 ? 1 : 0 ;
    $('#ribbon').stop().fadeTo(800, opacity);      

});
于 2013-04-03T09:33:12.410 に答える