页面滚动到指定位置

 经常不记得代码,在这里总截下,方便以后查看:

方法1:使用锚点 (不多说百度下 比较多)

方法2:jQuery实现

$(document).ready(function (){  
            $("#scroll2").click(function (){      //无过渡效果
                $('html, body').scrollTop(offset ); 
            });

            $("#scroll2").click(function (){     //平滑滚动到指定位置
                $('html, body').animate({  
                    scrollTop: offset        //offset,数值你要到滚动的位置 
                }, 2000);  
            });  
        });  

    Js 实现

用 requstAnimationFrame(function) 回调可以实现平滑滚动,无需使用计时器

posted @ 2016-07-29 10:55  为师灭了你  阅读(490)  评论(0编辑  收藏  举报