mainSlider.js 960 B

12345678910111213141516171819202122232425262728293031323334
  1. app.directive('mainSlider',['$interval','$timeout',function($interval,$timeout){
  2. return {
  3. restrict: 'E',
  4. scope: {},
  5. replace: true,
  6. templateUrl: './app/views/main-slider.html',
  7. controller: function($scope){
  8. $scope.currentSlide = 0;
  9. $scope.slides = [
  10. 'content/images/main-page-slider-image1.jpg',
  11. 'content/images/main-page-slider-image2.jpg',
  12. 'content/images/main-page-slider-image3.jpg'
  13. ]
  14. var runInterval = function(){
  15. $scope.sliderInterval = $interval(function(){
  16. if($scope.currentSlide == $scope.slides.length - 1){
  17. $scope.currentSlide = 0;
  18. } else{
  19. $scope.currentSlide++;
  20. }
  21. },7000)
  22. }
  23. runInterval();
  24. $scope.selectImage = function(imageUrl){
  25. $scope.currentSlide = $scope.slides.indexOf(imageUrl);
  26. $interval.cancel($scope.sliderInterval);
  27. runInterval();
  28. }
  29. }
  30. }
  31. }]);