I want to add the Auto scroll effect as in the demo portfolio page provided by FreeCodeCamp .
Hi,
You can do it with the JavaScript. Study the JS of the demo. The last block in JS panel does what you want:
$(function() {$('body').on('click', 'a.scrollable', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({scrollTop: $($anchor.attr('href')).offset().top},1500,'easeInOutExpo');
event.preventDefault();
});
});
You need to apply class scrollable
to the menu links. Then, the href
value of those links need to match with id
values of respective sections and then it should work.
Hope that helps
I don’t know JS.
should I just paste this code in the JS panel and add href="#id" and class=“scrollable” ?
Yes, you can try doing that. It should work.
You could try looking at window.scrollBy() or window.scrollTo(). These are useful JavaScript commands that help you deal with scrolling. I imagine you could write a function that slowly scrolls by a certain amount…
No. I can’t write one . However the problem has been solved but thanks for your help and