Javascript 悬停在幻灯片上时如何暂停角度间隔计时器

Javascript 悬停在幻灯片上时如何暂停角度间隔计时器,javascript,css,angularjs,Javascript,Css,Angularjs,当鼠标光标悬停在其中一张幻灯片上时,为什么我可以在我的代码中放置一个eventlisterner使计时器停止暂停 您可以使用ng mouseenter和ng mouseleave指令停止和启动计时器,更新了plunker: $scope.stopAuto=function(){ log('tickCtrl.stopAuto()已触发'); 中频(定时器){ $interval.cancel(计时器); 定时器=未定义; } } {{job.jobTitle} {{job.sector}

当鼠标光标悬停在其中一张幻灯片上时,为什么我可以在我的代码中放置一个eventlisterner使计时器停止暂停


您可以使用ng mouseenter和ng mouseleave指令停止和启动计时器,更新了plunker:

$scope.stopAuto=function(){
log('tickCtrl.stopAuto()已触发');
中频(定时器){
$interval.cancel(计时器);
定时器=未定义;
}
}
  • {{job.jobTitle} {{job.sector}

$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;
};
$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>