Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JQuery时,滚动功能工作不正常?_Jquery - Fatal编程技术网

使用JQuery时,滚动功能工作不正常?

使用JQuery时,滚动功能工作不正常?,jquery,Jquery,我有这个代码&当我单击#down时,页面向下滚动20,这是正确的。当我点击#up时,页面向右滚动到顶部,这是错误的,因为我只希望页面向上滚动20。以下是我正在使用的代码: $('#up').click(function(){ $('html, body').animate({ scrollTop: $(this).offset().top -= 20 }); return false; }); $('#down').click(function(){

我有这个代码&当我单击
#down
时,页面向下滚动20,这是正确的。当我点击
#up
时,页面向右滚动到顶部,这是错误的,因为我只希望页面向上滚动20。以下是我正在使用的代码:

$('#up').click(function(){
    $('html, body').animate({
        scrollTop: $(this).offset().top -= 20
    });
    return false;
});

$('#down').click(function(){
    $('html, body').animate({
        scrollTop: $(this).offset().top += 20
    });
    return false;
}); 

任何输入都将非常感谢,因为正确的语法是-=,而不是=-(这会导致值为-20,因此会滚动到顶部)。

我尝试过这一点,但它最终会执行与
#down
函数类似的操作