Scroll to top and bottom with mootools
You can also be interested in:
Months has passed since my last post (work, travels, marriage...) so now an easy one before detoxing myself from internet and programming and enjoying my journey to South Africa.
Let's see a way to implement the scroll to top and scroll to bottom buttons with mootools.
A bit of style
The two buttons are positioned at a fixed distance from top and bottom of the viewport. I've used font-awesome icons in my example as you will see in the js code.
.scroll { position: fixed; color: #e7e7e7; cursor: pointer; } .scroll-to-top { bottom: 70px; right: 20px; } .scroll-to-bottom { top: 80px; right: 20px; }
Javascript
Actually the Fx.Scroll class of the mootools-more package is required, it's not mandatory, you may animate the motion through css3 and do some more calculating, but now I'm not dealing with performance.
window.addEvent('load', function() { var checkScroll = function() { var body_scroll = document.body.getScroll(); to_top.setStyle('visibility', body_scroll.y > 0 ? 'visible': 'hidden'); to_bottom.setStyle('visibility', (body_scroll.y + window.getCoordinates().height) < window.getScrollSize().y ? 'visible': 'hidden'); } var scroll_fx = new Fx.Scroll(window); var to_top = new Element('span.scroll.scroll-to-top.fa.fa-3x.fa-arrow-circle-up') .addEvent('click', function() { scroll_fx.toTop(); }) .inject(document.body); var to_bottom = new Element('span.scroll.scroll-to-bottom.fa.fa-3x.fa-arrow-circle-down') .addEvent('click', function() { scroll_fx.toBottom(); }) .inject(document.body); checkScroll(); window.addEvent('scroll', function(e) { checkScroll(); }) })
Your Smartwatch Loves Tasker!
Your Smartwatch Loves Tasker!
Featured
Archive
- 2021
- 2020
- 2019
- 2018
- 2017
- Nov
- Oct
- Aug
- Jun
- Mar
- Feb
- 2016
- Oct
- Jun
- May
- Apr
- Mar
- Feb
- Jan
- 2015
- Nov
- Oct
- Aug
- Apr
- Mar
- Feb
- Jan
- 2014
- Sep
- Jul
- May
- Apr
- Mar
- Feb
- Jan
- 2013
- Nov
- Oct
- Sep
- Aug
- Jul
- Jun
- May
- Apr
- Mar
- Feb
- Jan
- 2012
- Dec
- Nov
- Oct
- Aug
- Jul
- Jun
- May
- Apr
- Jan
- 2011
- Dec
- Nov
- Oct
- Sep
- Aug
- Jul
- Jun
- May