【问题标题】:First Transition not smooth jQuery fade in/out第一个过渡不平滑jQuery淡入/淡出
【发布时间】:2012-08-04 21:20:18
【问题描述】:

我有一些循环遍历一系列 div 的 jQuery 代码。我有它,所以当前的 div 淡出,然后下一个 div 淡入它的位置。问题出在第一次转换时,可见的 div 并没有淡出,它只是消失了。在第一次过渡之后,其余的过渡是平滑的,具有适当的淡入/淡出运动。以下是 div 的示例:

<div id="testimonials">
    <div class="testimony current">
        <p>Text1</p>
    </div>
    <div class="testimony">
        <p>Text2</p>
    </div>
</div>

以下是用于过渡的 jQuery:

$(document).ready(function() {
    var cycle = window.setInterval(next, 6000);

    function next() {
        $('#testimonials .current').removeClass('current').fadeOut(500).next().add('#testimonials div:first').last().fadeIn(2000).addClass('current');
    }
});

你可以在http://jrubins.webfactional.com/tamid/vision.php看到尴尬的第一次转换

【问题讨论】:

    标签: jquery


    【解决方案1】:

    改变调用fadeOut()removeClass()方法的顺序,试试这个:

    function next() {
       $('#testimonials .current').fadeOut(500, function(){
           $(this).removeClass('current')
       }).next()...
    }
    

    【讨论】:

    • 是的,如果您查看该网站,您会看到代码已根据您的建议进行了更新,但效果相同
    • @jrubins 是的,显然元素的 display 属性设置为 none 会发生这种效果。尝试使用fadeOut 回调函数。
    • 我不明白为什么它会发生在第一次转换...?
    • @jrubins 应该和动画队列有关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    相关资源
    最近更新 更多