<!-- Elevator wrapper - Scroll to top utility -->
<div class="elevator-wrapper"></div>



<!-- Juck for a demo page -->
<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 - Scroll back to top utility CSS
// ==========================================

.elevator {
  display: inline-block;
  height: 48px;
  width: 48px;
  position: fixed;
  right: 20px;
  bottom: 20px;
  box-shadow: 0 0 10px fade(black, 5%); // rgba(0, 0, 0, 0.05);
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
  border-radius: 50%;
  text-decoration: none;
  background-image: none;
  background: fade(black, 70%); // rgba(0, 0, 0, 0.7);
  -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 {
    /* the button becomes 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%); // rgba(0, 0, 0, 0.8);
    .fa {
      color: white; // #fff
      top: 5px;
    }
  }
  @media (max-width: 768px) {
    /* only show elevator on desktop screen */
    display: none !important;
  }
}


/**
 * Junk for a demo page
 */
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 - Scroll back to top utility JS
  // ========================================

  // append necessary class
  // should have already contain wrapper on a page.
  // <div class="elevator-wrapper"></div>
  $('.elevator-wrapper').append('<div class="elevator"><i class="fa fa-chevron-up" aria-hidden="true"></i></div>');

  // browser window scroll (in pixels) after which the "back to top" link is shown
  var offset = 300,
    // duration of the top scrolling animation (in ms)
    scroll_top_duration = 700,
    // grab the "back to top" link
    $back_to_top = $('.elevator');

  // hide or show the "back to top" link
  $(window).scroll(function () {
    ($(this).scrollTop() > offset) ? $back_to_top.addClass('elevator-is-visible') : $back_to_top.removeClass('elevator-is-visible');
  });

  // smooth scroll to top
  $back_to_top.on('click', function (event) {
    event.preventDefault();
    $('body,html').animate({
      scrollTop: 0
      }, scroll_top_duration
    );
  });

})(jQuery);

External CSS

  1. //maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css
  2. //maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css

External JavaScript

  1. //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js