19 Jan 2014

Animate Page Scroll

Web developers are always eager to add dynamic effects to static web pages. The advent of jQuery simplified much of its hurdles. A common feature nowadays in modern websites is the animation of page scroll. It can be achieved with just 3 lines of jQuery code.
Here's it. The code will animate scrolling when clicked on anchors with class menu-link.

jQuery('a.menu-link').click(function(e){
e.preventDefault();
var href= jQuery(this).attr("href");
jQuery('html, body').animate({
scrollTop: jQuery(href).offset().top - 50}, 1000); });