Tags

, , ,

First Method Using ID’s

<a href="#div1">Go To Div 1</a>


<div id="div1"></div>

$('a[href^="#"]').on('click', function(event) {
    var target = $( $(this).attr('href') );
    if( target.length ) {
        event.preventDefault();
        $('html, body').animate({
            scrollTop: target.offset().top
        }, 1000);
    }
});

 

Second Method Using Classes

<a href="#" onClick="goToScroll('specificEle')">Go To Div that have class name specficEle</a>


<div class="specificEle"></div>

function goToScroll(e){
    $('html, body').animate({
        scrollTop: $("."+e).offset().top
    }, 1000);
}  

 

See It In Action

 

Advertisements