On button click I want to scroll a specific div. Make sure I don't want to use jQuery.
-
Possible duplicate of Scroll / Jump to id without jQueryBaldráni– Baldráni2018-09-13 09:40:29 +00:00Commented Sep 13, 2018 at 9:40
-
You can use a hyperlink and a hash fragment. Or you could use one of the solution linked to calculate the position of the element you want to scroll to.Shilly– Shilly2018-09-13 09:41:32 +00:00Commented Sep 13, 2018 at 9:41
-
1Possible duplicate of Scroll to specific div on (click) in AngularBrank Victoria– Brank Victoria2018-09-13 09:41:57 +00:00Commented Sep 13, 2018 at 9:41
Add a comment
|
2 Answers
You need to use $anchorScroll concept in angular refer example:
'use strict';angular.module('anchorScrollExample', []).controller('ScrollController', ['$scope', '$location', '$anchorScroll',
function($scope, $location, $anchorScroll) {
$scope.gotoBottom = function() {
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
};
}]);})(window.angular);
Here 'bottom' is your div id where you want to scroll and 'gotoBottom(). is function on button click