Portal Button to Scroll to Bottom of Page

Andrew Bettcher
Kilo Sage

Hi,

I found this post which gives me a button with an arrow it. When I click the button it takes me to the top of the page. It works.

I need to amend it to take me to the bottom of the page instead but I can't work out what part of the code is taking me to the top.

The button hide/show was behaving strangely and so I removed the part of the code that decides if it should be hidden or not.

As far I understand it is working out how far you scrolled down and then scrolling you back up by the same amount. Is that right?

This the current client controller code.

function($scope, spUtil, $element) {
	var c = this;
	$element.show();
	//var height = c.options.height_from_top || 300;
	//height = parseInt(height);
	//var lastScrollTop = 0;
	var container = angular.element('.sp-scroll');

	container.on("scroll", function() {
		var currentScroll = angular.element(container).scrollTop();
		//if(lastScrollTop > currentScroll && lastScrollTop > height && currentScroll > height) // moving up
		//	$element.show();
		//else
		//	$element.show();
		lastScrollTop = currentScroll;
	});


	$scope.goBottom = function() {
		spUtil.scrollTo('.sp-scroll', 300);
	}

}

I've worked out that the last 300 controls the speed at which is scrolls (the higher number the slower it scrolls).

So, how do I make it scroll down instead? All the way down is fine but if I could specify how far then even better.

1 ACCEPTED SOLUTION

Ct111
Tera Sage

Hello, Here an example is given to scroll down via button.

Please, take this as reference and devise your solution. https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_scrollintoview

 

Note : for testing purpose first click on Run and then click on Scroll to see the output.

 

Mark my Answer as Correct and Helpful if it helps

View solution in original post

2 REPLIES 2

Ct111
Tera Sage

Hello, Here an example is given to scroll down via button.

Please, take this as reference and devise your solution. https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_scrollintoview

 

Note : for testing purpose first click on Run and then click on Scroll to see the output.

 

Mark my Answer as Correct and Helpful if it helps

Thank you so much.

 

That is very useful. However, in the end I cheated a little. I added a new menu item that links to an anchor using the div code of the section that I wanted to get to and added the Scroll To Top button with some modifications to get users back to the top.