I'm trying to show an arrow icon to be used as "go to top" button, but only after some scrolling done by the user. The code used to work great using jquery
, but I'm having hard time to achieve the same effect using angular
. At the moment, the arrow is always seen in the bottom right corner of the screen.
JSfiddle here.
JS:
var myApp = angular.module('app',[]);
myApp.controller('ctrl', ['$scope', function($scope) {
//detect scroll
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
console.log(scroll);
if(scroll>500 || scroll==undefined){
$scope.showUpArrow = false;
}else{
$scope.showUpArrow = true;
}
});
}]);
HTML:
<div ng-app="app">
<div ng-controller="ctrl">
<div ng-hide="showUpArrow" id="goUp-cont">
<a href="#top"><i class="fa fa-arrow-up fa-4x" id="goUp"></i></a>
</div>
</div>
</div>