On button click I want to scroll a specific div. Make sure I don't want to use jQuery.
Asked
Active
Viewed 628 times
-1
-
Possible duplicate of [Scroll / Jump to id without jQuery](https://stackoverflow.com/questions/13266746/scroll-jump-to-id-without-jquery) – Baldráni Sep 13 '18 at 09: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 Sep 13 '18 at 09:41
-
1Possible duplicate of [Scroll to specific div on (click) in Angular](https://stackoverflow.com/questions/51212900/scroll-to-specific-div-on-click-in-angular) – Brank Victoria Sep 13 '18 at 09:41
2 Answers
0
Give id for that div and use
document.getElementById("id").scrollIntoView();
<div id="whatever">
<--do things -->
</div>
<script>
document.getElementById("whatever").scrollIntoView();
</script>

S Meena Padnekar
- 1
- 3
0
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

saumil_
- 304
- 2
- 11