I'm working on an angular5 app. In that app, I need to go down to the current page based on data. ScrollToTop
is working fine, I want to go down to the current page. Is there any way like scrollTop in angular5.
Asked
Active
Viewed 126 times
-1

Joe Warner
- 3,335
- 1
- 14
- 41

Siva Krishna Maddipati
- 9
- 1
- 5
-
4Possible duplicate of [Scroll Automatically to the Bottom of the Page](https://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) – lin Mar 12 '18 at 13:12
-
Did you try the javascript `document.querySelector('#ComponentId').scrollIntoView();` ? – ibenjelloun Mar 12 '18 at 13:13
-
Not an answer but just take not of a function called focus, try and make use of that function on the last generated data. – Wale Mar 12 '18 at 13:15
2 Answers
0
You can scroll to the bottom of the page with this line:
window.scrollTo(0,document.body.scrollHeight);
If you want to scroll a specific html element, try this one:
window.scrollTo(0,document.querySelector(".scrollingContainer").scrollHeight);
See also this demo, it can help you.

Laiso
- 2,630
- 3
- 16
- 32
-1
You can make it using animate
and scrollTop
from jQuery as following:
HTML :
<a href="#contact">Contact</a>
<!-- set the H2 deep down in the page -->
<h2 id="contact">Contact</h2>
jQuery :
$('a[href^="#"]').on('click', function(){
var the_id = $(this).attr("href");
if (the_id === '#') {
return;
}
$('html, body').animate({
scrollTop:$(the_id).offset().top
}, 'slow');
return false;
});

kevinniel
- 1,088
- 1
- 6
- 14
-
2
-
jQuery is made with javascript, so i'd say it is possible in javascript, but anyway you'll need to use jQuery or Javascript to do this. – kevinniel Mar 12 '18 at 13:37
-
It is not recommended practice to use jQuery and Angular. Not the downvoter – mxr7350 Mar 12 '18 at 13:43
-
Ow yeah sorry, @mxr7350 is right, didn't see it was on angular, sry for that :/ – kevinniel Mar 12 '18 at 13:44
-
-
@SivaKrishnaMaddipati You can use third party scroll module like `angular2-infinite-scroll ` – Laiso Mar 12 '18 at 13:45
-
-
@Laiso i want to navigate the control to the bottom of the page, without scroll. – Siva Krishna Maddipati Mar 14 '18 at 05:30