Simple Scroll to Top

HTML
<html> <body id="top"> <div class="cover"> <div class="navbar"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-ex-collapse"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#"><span>Brand</span></a> </div> <div class="collapse navbar-collapse" id="navbar-ex-collapse"> <ul class="nav navbar-nav navbar-right"> <li class="active"> <a href="#about">About</a> </li> <li> <a href="#contacts">Contacts</a> </li> </ul> </div> </div> </div> <div class="background-image-fixed cover-image" style="background-image: url(https://unsplash.imgix.net/photo-1418065460487-3e41a6c84dc5?q=25&fm=jpg&s=127f3a3ccf4356b7f79594e05f6c840e);"></div> <div class="container"> <div class="row"> <div class="col-md-12 text-center"> <h1 class="text-inverse">Heading</h1> <p class="text-inverse">Lorem ipsum dolor sit amet, consectetur adipisici eli.</p> <br> <br> <a class="btn btn-lg btn-primary" href="#about">Click me</a> </div> </div> </div> </div> <div id="about" class="section"> <div class="container"> <div class="row"> <div class="col-md-6"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/placeholder.png" class="img-responsive"> </div> <div class="col-md-6"> <h1 class="text-primary">A title</h1> <h3>A subtitle</h3> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p> </div> </div> </div> </div> <div class="section"> <div class="container"> <div class="row"> <div class="col-md-6"> <h1 class="text-primary">A title</h1> <h3>A subtitle</h3> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.</p> </div> <div class="col-md-6"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/placeholder.png" class="img-responsive"> </div> </div> </div> </div> <div class="section"> <div class="container"> <div class="row"> <div class="col-md-12"> <h1 id="contacts" class="text-center text-primary">Team</h1> <p class="text-center">We are a group of skilled individuals.</p> </div> </div> <div class="row"> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> <div class="col-md-4"> <img src="http://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png" class="center-block img-circle img-responsive"> <h3 class="text-center">John Doe</h3> <p class="text-center">Developer</p> </div> </div> </div> </div> <div class="scrolly-top"><a href="#top"><i class="fa fa-arrow-up" aria-hidden="true"></i></a></div> </body> </html>
CSS
.scrolly-top{ position: fixed; background-color: #000; bottom:30px; right:30px; color:#fff; text-transform:uppercase; display: none; -webkit-opacity: 0.5; opacity: 0.5; transition: all 0.5s; text-align:center; font-size:24px; } .scrolly-top:hover{ -webkit-opacity:1; opacity: 1; } .scrolly-top a{ display:block; color:#fff !important; padding:10px; text-decoration: none !important; }
JAVASCRIPT
$( document ).ready(function() { $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html, body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); }); $(document).scroll(function() { var y = $(this).scrollTop(); if (y > 40) { $('.scrolly-top').fadeIn(); } else { $('.scrolly-top').fadeOut(); } });
Expand for more options Login