javascript中滚动到指定位置

javascript中滚动到指定位置

  • 方法一

    1
    2
    3
    4
    5

    //主要运用到了$(selector).animate(styles,speed,easing,callback)和scrollTop函数
    $("body,html").animate({
    scrollTop: 200 //让body的scrollTop等于pos的top,就实现了滚动
    }, 200);
  • jq滚动方法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    $("#text1").click(function(){

    $("html,body").animate(

    {scrollTop:$($("#text1").attr('href')).offset().top},500 /*scroll实现定位滚动*/

    );/*让整个页面可以滚动*/

    return false;