jquery scroll to the top

    <Script> 
        $ .fn.scrollTo = function (Options) { 

            var Defaults = { 

                toT: 0 , // scroll target position 

                durTime: 500 , // transition animation Time 

                Delay: 30 , // timer 

                the callback: null  // callback 

            }; 

            var the opts = $ .extend (Defaults, Options), 

                Timer = null , 

                _this = the this ,

                curtop = _this.scrollTop (), // scrollbar current location 

                subTop = opts.toT - curtop, // scroll target position and the present position difference 

                index = 0 , 

                DUR = Math.round (opts.durTime / the opts .delay), 

                smoothScroll = function (T) { 

                    index ++ ; 

                    var per Math.round = (subTop / DUR); 

                    IF (index> = DUR) { 

                        _this.scrollTop (T); 

                        window.clearInterval (Timer); 

                        IF (opts.callback &&typeof opts.callback == 'function') {

                            opts.callback();

                        }

                        return;

                    } else {

                        _this.scrollTop(curTop + index * per);

                    }

                };

            timer = window.setInterval(function () {

                smoothScroll(opts.toT);

            }, opts.delay);

            return _this;

        };


        $("body").scrollTo({ toT: 0 });
    </script>

 

Guess you like

Origin www.cnblogs.com/hofmann/p/11853573.html