Forked from sean-hill/AngularJS Back To Top Directive
Last active
June 5, 2017 13:15
-
-
Save atefBB/41acec1db8a69003a8b8d7c7e57bb5a4 to your computer and use it in GitHub Desktop.
AngularJS Back To Top Directive
This file contains 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 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