1

This question has been asked many times, but most of them were unanswered and some of the solutions I tried did not work out.

In my page (angularjs), only the left half of it scrollable, I have put it inside a div element. Now how do I implement scroll to top inside the scrollable div.

For the entire page, i was able to do it with the below code

/** scroll to top function */
$scope.scrollToTop = function($var) {

    $('html, body').animate({
        scrollTop: 0
    }, 'fast');
};

How do I modify it so only in the left part we can scroll to top

2
  • 1
    you can use id or class of div as a selector $('sample').animate({scrollTop:0},'fast'); Commented Jul 23, 2015 at 8:47
  • worked like a charm thanks, dont know why I dint try that before... keep it as an answer so others will find it useful Commented Jul 23, 2015 at 9:08

2 Answers 2

3

Try to do it like with class or id

$('sample').animate({
 scrollTop:0
},'fast');
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

$('html, body').animate(
       {scrollTop: $('#your-element').position().top} , '600', function() { 
            return false; 
       }
);

Here is a working example: http://jsfiddle.net/4wdfb6cu/

1 Comment

Try the fiddle provided

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.