Add value to existing jquery

Asked 1 years ago, Updated 1 years ago, 46 views

j$( document).ready(function(){
  $('a[href^="#"]').click(function(){
    var speed = 800;
    var href=$(this).attr("href");
    var target=$(href=="#"||href==""?'html':href);
    var position = target.offset().top;
    $("html, body").animate({scrollTop:position}, speed, "swing");
    return false;
  });
});

Here is the code used for scrolling top, and I would like to value var position.
For example, how can I change the code if I want to bring the scroll position -50px above or below the current code position?

I'm sorry if it's difficult to understand and basic questions.Thank you for your cooperation.

jquery

2022-09-30 17:00

1 Answers

I think I just need to add +50 to the position.

var position=target.offset().top+50;


2022-09-30 17:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.