Forked from sean-hill/AngularJS Back To Top Directive
Created
November 28, 2017 13:46
-
-
Save sajjadabdi/fb7bf3343f14d717ab8e50798086e973 to your computer and use it in GitHub Desktop.
AngularJS Back To Top Directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AngularJS Back To Top Directive. | |
Uses AngularJS, jQuery, Font Awesome, and SCSS. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Back to top Directive | |
angular.module('app.directives') | |
.directive('backToTop', function(){ | |
return { | |
restrict: 'E' | |
, replace: true | |
, template: '<div class="back-to-top"><i class="fa fa-chevron-up"></i></div>' | |
, link: function($scope, element, attrs) { | |
$(window).scroll(function(){ | |
if ($(window).scrollTop() <= 0) { | |
$(element).fadeOut(); | |
} | |
else { | |
$(element).fadeIn(); | |
} | |
}); | |
$(element).on('click', function(){ | |
$('html, body').animate({ scrollTop: 0 }, 'fast'); | |
}); | |
} | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Back to top styles | |
.back-to-top { | |
position: fixed; | |
bottom: 20px; | |
right: 20px; | |
z-index: 1; | |
width: 50px; | |
height: 50px; | |
background: #DDD; | |
opacity: 0.5; | |
display: none; | |
&:hover { | |
opacity: 1; | |
cursor: pointer; | |
} | |
i { | |
font-size: 25px; | |
padding: 12px; | |
color: #FFF; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment