Jquery缓和和动画

rd4*_*d42 0 javascript jquery easing

我从这里抓住了这个紧凑的新闻阅读器下面是点击链接时动画放松和简化预览的代码.我将整个页面的尺寸从300的高度更改为600.我做了一些谷歌搜索,jquery的动画部分动画了元素的CSS属性.所以我从那里开始工作.以为我有事情可行,但事实并非如此,我想我会再次从头开始.

任何人都可以解读这个吗?例如,我只是猜测,"动画页面元素的顶级css到-300px ...我不明白的其余部分.

感谢您提供任何帮助,骚扰或指示.

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

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;
                });
            });
Run Code Online (Sandbox Code Playgroud)

jap*_*ott 5

我会解释;

$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
        }
    );
Run Code Online (Sandbox Code Playgroud)

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