Mohaideen
Mohaideen

Reputation: 303

offsetTop is not working

i am using scrollTo. but offsetTop is not working. I want go to that position with top 300px

$('#tab1').on('click', function(){
        $('body').scrollTo('#services38',{duration:'slow', offsetTop : '300'});
        //$('body').scrollTo(400);
    });

Upvotes: 0

Views: 1298

Answers (2)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85575

Try this:

$('#tab1').on('click', function(){
$('html,body').animate({
        scrollTop: '300'
    }, 1000, 'linear');
});

Upvotes: 1

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28578

offsetTop is read-only, while scrollTop is read/write. So you need to use second one here.

To make it animated effect try:

$('body').animate({
    scrollTop: $("#services38").offset().top
}, 2000);

Upvotes: 1

Related Questions