Subtract from an integer using jquery

后端 未结 3 1452
北恋
北恋 2021-01-27 06:20

I want to scroll to a div each time user presses j key. Here is the code for it.

$(function() {
    function scroll(direction) {

        var s         


        
3条回答
  •  余生分开走
    2021-01-27 07:18

    Try putting some space between your minus symbol so it does not get mistaken for a dash.

    $('html, body').animate({"scrollTop": $(scroll).offset().top - 50});
    

    or save your mathematics in a variable first

    var scrollMinusFifty = $(scroll).offset().top - 50;
    $('html, body').animate({"scrollTop":scrollMinusFifty});
    

提交回复
热议问题