<div class="elevator-wrapper"></div>
<div style="height:2000px;">
<h3>Scroll down</h3>
<h3><i class="fa fa-arrow-down"></i></h3>
<div class="alert alert-info">
<h4><i class="fa fa-lightbulb-o"></i> Scroll 300px to see elevator button</h4>
When you scroll more than 300px you will see elevator button on the right corner. Icon on elevator will slowly bounce upward when you hover on it. If you click the elevator button the page will smoothly scroll back to top on 700ms speed.
</div>
<div class="alert alert-warning">
<h4><i class="fa fa-warning"></i> View demo on desktop screen with more than 768px</h4>
Looks like you're viewing from less than 768px screen. Defaultly elevator button is only visible in desktop screen with more than 768px.
</div>
</div>
.elevator {
display: inline-block;
height: 48px;
width: 48px;
position: fixed;
right: 20px;
bottom: 20px;
box-shadow: 0 0 10px fade(black, 5%);
overflow: hidden;
white-space: nowrap;
cursor: pointer;
border-radius: 50%;
text-decoration: none;
background-image: none;
background: fade(black, 70%);
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
visibility: hidden;
opacity: 0;
&.elevator-is-visible {
visibility: visible;
opacity: 1;
z-index: 999;
}
.fa {
color: white;
margin: 0;
padding: 0;
position: relative;
left: 14.5px;
top: 12.5px;
font-size: 20px;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
&:hover {
background: fade(black, 80%);
.fa {
color: white;
top: 5px;
}
}
@media (max-width: 768px) {
display: none !important;
}
}
body{background: #eee ;font-family: 'Open Sans', sans-serif;}h3{font-size: 30px; font-weight: 400;text-align: center;margin-top: 50px;}h3 i{color: #444;}
.alert {
margin: 25px 25% 0 25%;
&.alert-info {
@media (max-width: 768px) {
display: none !important;
}
}
&.alert-warning {
@media (min-width: 768px) {
display: none !important;
}
}
}
View Compiled
(function ($) {
'use strict';
$('.elevator-wrapper').append('<div class="elevator"><i class="fa fa-chevron-up" aria-hidden="true"></i></div>');
var offset = 300,
scroll_top_duration = 700,
$back_to_top = $('.elevator');
$(window).scroll(function () {
($(this).scrollTop() > offset) ? $back_to_top.addClass('elevator-is-visible') : $back_to_top.removeClass('elevator-is-visible');
});
$back_to_top.on('click', function (event) {
event.preventDefault();
$('body,html').animate({
scrollTop: 0
}, scroll_top_duration
);
});
})(jQuery);