javascript - Jquery 缓动和动画

标签 javascript jquery easing

我从 here 获取了这款紧凑型新闻阅读器下面是单击链接时动画缓入和缓出预览的代码。我将整个页面的尺寸从 300 的高度更改为 600。我进行了一些谷歌搜索,jquery 的动画部分对元素的 CSS 属性进行了动画处理。所以我从那里开始工作。以为我的工作正常,但事实并非如此,所以我想我会从头开始。

有人能解释一下这句话吗?例如,我只是猜测,“将页面元素的顶部 css 设置为 -300px...该行的其余部分我不明白。

感谢您的任何帮助、骚扰或指点。

$current.stop().animate({'top':'-300px'},600,'easeOutBack',function(){
                            $(this).css({'top':'310px'});

sdfadssf

            $items.each(function(i){
                var $item = $(this);
                $item.data('idx',i+1);

                $item.bind('click',function(){
                    var $this       = $(this);
                    $cn_list.find('.selected').removeClass('selected');
                    $this.addClass('selected');
                    var idx         = $(this).data('idx');
                    var $current    = $cn_preview.find('.cn_content:nth-child('+current+')');
                    var $next       = $cn_preview.find('.cn_content:nth-child('+idx+')');

                    if(idx > current){
                        $current.stop().animate({'top':'-300px'},600,'easeOutBack',function(){
                            $(this).css({'top':'310px'});
                        });
                        $next.css({'top':'310px'}).stop().animate({'top':'5px'},600,'easeOutBack');
                    }
                    else if(idx < current){
                        $current.stop().animate({'top':'310px'},600,'easeOutBack',function(){
                            $(this).css({'top':'310px'});
                        });
                        $next.css({'top':'-300px'}).stop().animate({'top':'5px'},600,'easeOutBack');
                    }
                    current = idx;
                });
            });

最佳答案

我解释一下;

$current. //the element you are on
    stop(). //stop all running animations
    animate( //start a new animation
        {'top':'-300px'}, //animate till this element's top style is -300px
        600, //the animation will take 600ms
        'easeOutBack', //it will use the EaseOutBack easing function
        function(){ //callback, that gets called as soon as the animation finishes
            $(this).css({'top':'310px'}); //set the element's top style to 310px
        }
    );

换句话说,这个函数并没有做任何非常聪明的事情。它会动画化,最后它会跳到另一个地方。 无论如何,希望我能有所帮助:)

关于javascript - Jquery 缓动和动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8961808/

相关文章:

javascript - 如何使用 javascript/jquery 用标签包装元素的同级文本?

jquery - 动画 css 更改 (jQuery)

javascript - jQuery Cycle 插件 : scroll slides horizontally at constant speed, 没有缓动

javascript - 将 coldfusion 查询结果作为 javascript 对象放入 javascript 数组(谷歌地图)

javascript - 变量 isConnected 未更改

javascript - JS中的触摸板滚动检测,没有库

cocos2d-iphone - 像 CCSprite 对象一样移动 Box2d 实体

javascript - Node.js 密码重置

javascript - 当用户将鼠标悬停在 html 文档中的静态图像上时如何显示谷歌地图

jquery - 子 div 的宽度应为 100%