Is there a why i can place an eventlisterner to my code for the timer to stop pause when the mouse cursor hovers over one of the slides?
$scope.jobNotification = 0;
var timer;
$scope.startAuto = function() {
timer = $interval(function(){
$scope.jobNotification = ($scope.jobNotification + 1) % $scope.jobs.length;
}, 5000);
};
$scope.isActive = function (index) {
return $scope.jobNotification === index;
};
$scope.showJobNotification = function (index) {
if (timer){
$interval.cancel(timer);
$scope.startAuto();
}
$scope.jobNotification = index;
};
You could use ng-mouseenter and ng-mouseleave directives to stop and start your timer, updated plunker http://plnkr.co/edit/09bf3T?p=preview:
$scope.stopAuto = function() {
console.log('tickCtrl.stopAuto() triggered');
if(timer) {
$interval.cancel(timer);
timer = undefined;
}
}
<ul ng-mouseover="stopAuto()" ng-mouseleave="startAuto()">
<li data-ng-repeat="job in jobs" ng-show="isActive($index)">
<h1>{{job.jobTitle}}</h1>
<p>{{job.sector}}</p>
</li>
</ul>