Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Scroll Automatically to the Bottom of the Page in Service Portal

salu
Mega Guru

Hello,

Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page.

window.scrollTo(0,document.body.scrollHeight); won't work as document won't work in API.

Thanks

Saranya

1 ACCEPTED SOLUTION

Hello Mansoor,


I got the solution for the same.



$scope.scrollTo = function(id) {



var old = $location.hash();


$location.hash(id);


$anchorScroll();


//reset to old to keep any additional routing logic from kicking in


$location.hash(old);


};



<sp-model form-model="::data.sc_cat_item" mandatory="mandatory" ng-click="scrollTo('e30904d54f83e200bb603f828110c721')"   ></sp-model>


View solution in original post

23 REPLIES 23

Vikas-Malhotra
Mega Guru

Hi Saranya,



Try this.



<button onclick="scrollWin(0, -50)">Scroll up</button>


<script>


function scrollWin(x, y) {
      window.scrollBy(x, y);
}
</script>




Regards,


Vikas


Hello Malhotra,


Where I need to add this?


I need to scroll botton of the page while answering the question. Didn't need any button for it.


Thanks


Saranya


mansoor3
Tera Contributor

Hi Saranya,



Try this link AngularJS - anchorscroll.



Where you can scroll to the element which have the id mentioned in the script.



$scope.gotoBottom = function() {
   
// set the location.hash to the id of
   
// the element you wish to scroll to.
  $location
.hash('bottom');//bottom is an element id

   
// call $anchorScroll()
  $anchorScroll
();
   
};



-Mansoor


-Mark correct or helpful as applicable


Hello Mansoor,


Thank you for the reply.


Sorry for the silly question.



Where I need to use it?


Is it in catalog widget or on change of my question variable?