Here is a solution using pure JavaScript instead of JQuery, in case you do not have the JQuery library.
JSFiddle
HTML Code:
<i id="icon" class="fa fa-arrow-circle-o-bottom"></i>
JavaScript Code:
// Function to detect when scrollbar reaches the bottom of the page
var detectScrollBarBottom = function() {
var windowHeight = (self.innerHeight) ? self.innerHeight : document.body.clientHeight; // Get window height
// Get current vertical scrollbar position
var scrollPosition = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
// Check if scrollbar reaches the bottom
if (document.body.scrollHeight <= (scrollPosition + windowHeight)) {
//alert('Bottom');
var iconElement = document.getElementById("icon");
iconElement.className = iconElement.className + " rotated";
} else {
var resetIcon = document.getElementById("icon");
resetIcon.className = "fa fa-arrow-circle-o-bottom";
}
}
// Register event on scrollbar
window.onscroll = detectScrollBarBottom;
// Smooth scroll function
var smoothScrollTo = function(element, target, duration) {
target = Math.round(target);
duration = Math.round(duration);
if (duration < 0) {
return Promise.reject("bad duration");
}
if (duration === 0) {
element.scrollTop = target;
return Promise.resolve();
}
var startTime = Date.now();
var endTime = startTime + duration;
var startTop = element.scrollTop;
var distance = target - startTop;
// Smoothstep interpolation function
var smoothStep = function(start, end, point) {
if(point <= start) { return 0; }
if(point >= end) { return 1; }
var x = (point - start) / (end - start);
return x*x*(3 - 2*x);
}
return new Promise(function(resolve, reject) {
var previousTop = element.scrollTop;
var scrollFrame = function() {
if(element.scrollTop != previousTop) {
reject("interrupted");
return;
}
var now = Date.now();
var point = smoothStep(startTime, endTime, now);
var frameTop = Math.round(startTop + (distance * point));
element.scrollTop = frameTop;
if(now >= endTime) {
resolve();
return;
}
if(element.scrollTop === previousTop && element.scrollTop !== frameTop) {
resolve();
return;
}
previousTop = element.scrollTop;
setTimeout(scrollFrame, 0);
}
setTimeout(scrollFrame, 0);
});
}
function scrollToTop() {
var bodyElement = document.querySelector('body');
smoothScrollTo(bodyElement, bodyElement.scrollTop - 2000, 600);
}
var myIcon = document.getElementById("icon");
myIcon.addEventListener('click', function() {
scrollToTop();
}, false);