akashrajkn
akashrajkn

Reputation: 2315

scroll to top inside a scrollable div angularjs

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

Upvotes: 1

Views: 1483

Answers (2)

Endre Simo
Endre Simo

Reputation: 11551

Try this:

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

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

Upvotes: 2

Shubham Nigam
Shubham Nigam

Reputation: 3944

Try to do it like with class or id

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

Upvotes: 3

Related Questions