Firefox 与 Safari 中流畅的 jQuery 动画

发布于 2024-09-16 06:10:09 字数 2118 浏览 2 评论 0原文

我喜欢 Safari 中的以下动画效果,但讨厌 Firefox 中的动画效果(单击事件名称,然后单击页面底部的“上一篇文章”或“下一篇文章”)。有没有办法像 Safari 中那样“平滑”动画?

编辑: 在 Firefox 中,当两个图像相互交叉时,会出现“白色闪光”。当页面向上滚动时,它看起来很不稳定(因为元素的高度发生了变化)。在 safari 中,这种“闪光”不会发生,并且动画导致的滚动更加平滑(一点也不生涩)......这是我描述它的最好方式。希望有帮助!


(我是一名 jQuery 业余爱好者,因此对当前状态的代码的任何其他评论将不胜感激!)

谢谢!

http://www.jesserosenfield.com/900number/news.html

//Prev Click
$('.prevSingle').click( function() {
       // Cache the ancestor
    var $ancestor = $(this).parent().parent().parent();
       // Get the next .newsSingle
    var $prev = $ancestor.prev('.newsSingle');
       // If there wasn't a next one, go back to the first.
    if( $prev.length == 0 ) {
        $prev = $ancestor.nextAll('.newsSingle').last();;
    }

    //Get the height of the next element
    var thisHeight = $prev.attr('rel');

    //Hide the current element
    $ancestor.animate({
            paddingBottom:'0px',
            top:'48px',
            height: '491px'
        }, 300);

        //Get the next element and slide it in      
    $prev.animate({
            top:'539px',
            height: thisHeight,
            paddingBottom:'100px'
        }, 300);
});

//Next Click
$('.nextSingle').click( function() {
       // Cache the ancestor
    var $ancestor = $(this).parent().parent().parent();
       // Get the next .newsSingle
    var $next = $ancestor.next('.newsSingle');
       // If there wasn't a next one, go back to the first.
    if( $next.length == 0 ) {
        $next = $ancestor.prevAll('.newsSingle').last();;
    }

    //Get the height of the next element
    var thisHeight = $next.attr('rel');

    //Hide the current element
    $ancestor.animate({
            paddingBottom:'0px',
            top:'48px',
            height: '491px'
        }, 300);

        //Get the next element and slide it in      
    $next.animate({
            top:'539px',
            height: thisHeight,
            paddingBottom:'100px'
        }, 300);
});

I love how the following animates in Safari, but hate how it does in firefox (click an event name, then click "previous post" or "next post" at the bottom of the page). Is there a way to "smooth out" the animation like it does it in Safari?

EDIT:
In firefox there is kind of a "flash of white" as the two images cross each other. It looks jerky as the page scrolls up (because of the height change of the elements). In safari, this "flash" doesn't happen, and the scrolling as a result of the animation is much smoother (not jerky at all)... that's the best way I can describe it. Hope that helps!


(i'm a jQuery amateur, so any other comments on the code in its current state would be much appreciated!)

thanks!

http://www.jesserosenfield.com/900number/news.html

//Prev Click
$('.prevSingle').click( function() {
       // Cache the ancestor
    var $ancestor = $(this).parent().parent().parent();
       // Get the next .newsSingle
    var $prev = $ancestor.prev('.newsSingle');
       // If there wasn't a next one, go back to the first.
    if( $prev.length == 0 ) {
        $prev = $ancestor.nextAll('.newsSingle').last();;
    }

    //Get the height of the next element
    var thisHeight = $prev.attr('rel');

    //Hide the current element
    $ancestor.animate({
            paddingBottom:'0px',
            top:'48px',
            height: '491px'
        }, 300);

        //Get the next element and slide it in      
    $prev.animate({
            top:'539px',
            height: thisHeight,
            paddingBottom:'100px'
        }, 300);
});

//Next Click
$('.nextSingle').click( function() {
       // Cache the ancestor
    var $ancestor = $(this).parent().parent().parent();
       // Get the next .newsSingle
    var $next = $ancestor.next('.newsSingle');
       // If there wasn't a next one, go back to the first.
    if( $next.length == 0 ) {
        $next = $ancestor.prevAll('.newsSingle').last();;
    }

    //Get the height of the next element
    var thisHeight = $next.attr('rel');

    //Hide the current element
    $ancestor.animate({
            paddingBottom:'0px',
            top:'48px',
            height: '491px'
        }, 300);

        //Get the next element and slide it in      
    $next.animate({
            top:'539px',
            height: thisHeight,
            paddingBottom:'100px'
        }, 300);
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文