Skip to content

Instantly share code, notes, and snippets.

@akashrajkn
Created July 27, 2015 18:26
Show Gist options
  • Save akashrajkn/4351531b513c43fca173 to your computer and use it in GitHub Desktop.
Save akashrajkn/4351531b513c43fca173 to your computer and use it in GitHub Desktop.
simple scroll to top function in AngularJS
/** scroll to top function in AngularJS */
angular.module('demoApp').controller('controller', ['$scope', function($scope) {
$scope.scrollToTop = function($var) {
// 'html, body' denotes the html element, to go to any other custom element, use '#elementID'
$('html, body').animate({
scrollTop: 0
}, 'fast'); // 'fast' is for fast animation
};
}]);
@akashrajkn
Copy link
Author

can be used in button as follows (here a bootstrap button is used) -

->button class = "btn btn-default" ng-click = "scrollToTop()"> Scroll to top</button

@sg28
Copy link

sg28 commented Feb 22, 2018

some cases $ is not a valid implementation

@yashvekaria
Copy link

I had tried in modal by making it as directive.
But didn't work as per expectation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment