supermishboy
supermishboy

Reputation: 99

Slow scroll for anchors

I have found this script for anchors on my page

$('.anchor').click(function (event) {
  event.preventDefault();
  var href = $(this).attr('href');
  var target = $(href);
  var top = target.offset().top;
  $('html,body').animate({
     scrollTop: top
  });
});

But, when i click on <div class="anchor">, my page jumps to the position. Is it possible to slow this scrolling?

Upvotes: 0

Views: 97

Answers (1)

Dhiraj
Dhiraj

Reputation: 33628

You can do something like this

$('html,body').animate({
   scrollTop: top
}, "slow");

.animate method looks like this.

.animate( properties [, duration ] [, easing ] [, complete ] )

By default the durations look like this

slow - 600, normal - 400, fast - 200.

If they are not suitable for your case then you can give your own duration

Upvotes: 1

Related Questions