如何滚动到一个部分?

时间:2017-02-01 06:00:37

标签: jquery html

问题:它滚动到底部而不是section2。也许scrollTop不是这样做的?我不确定。

https://jsfiddle.net/ocoeabmy/5/

 CODE (website not phone friendly)
 #include <stdio.h>
 #define PI 3.141593
 int main (){
     int degrees =10;
     double radians;
     printf("Degrees to Radians \n");

     while( degrees <= 360){
         radians = degrees*PI/180;
         printf("%6i %9.6f \n", degrees, radians);
        degrees +=10;
     }
 }
 END CODE

2 个答案:

答案 0 :(得分:0)

您可以使用此功能

function ScrollWindowToElement(ele) {
    var sc = $(ele[0]).offset().top;
    $('body,html').animate({
        scrollTop: (sc - 30)
    },
    'slow');
}

Your updated fiddle

答案 1 :(得分:-1)

试试这个:

您可以从jquery函数中删除700

 var target = $("#section2");
 $('#myPanel').animate({
   scrollTop: target.offset().top -100
 }, );
 //window.location.hash = "#" + "section3";

DEMO here