Created
July 27, 2015 18:26
-
-
Save akashrajkn/4351531b513c43fca173 to your computer and use it in GitHub Desktop.
simple scroll to top function in AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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 | |
}; | |
}]); |
some cases $ is not a valid implementation
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
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