mainSlider.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. var backOverlay = angular.element(document.querySelector('.main-slider-back-overlay'));
  9. $timeout(function(){
  10. backOverlay.css('transform', 'translateX(-100%)');
  11. },10)
  12. $scope.currentSlide = 0;
  13. $scope.canIClick = true;
  14. $scope.slides = [
  15. 'content/images/main-page-slider-image1.jpg',
  16. 'content/images/main-page-slider-image2.jpg',
  17. 'content/images/main-page-slider-image3.jpg'
  18. ]
  19. var runInterval = function(){
  20. $scope.sliderInterval = $interval(function(){
  21. if($scope.currentSlide == $scope.slides.length - 1){
  22. $scope.currentSlide = 0;
  23. } else{
  24. $scope.currentSlide++;
  25. }
  26. },7000)
  27. }
  28. runInterval();
  29. $scope.selectImage = function(imageUrl){
  30. if($scope.canIClick){
  31. $scope.canIClick = false;
  32. $scope.currentSlide = $scope.slides.indexOf(imageUrl);
  33. $interval.cancel($scope.sliderInterval);
  34. runInterval();
  35. $timeout(function(){
  36. $scope.canIClick = true;
  37. },3000)
  38. }
  39. }
  40. }
  41. }
  42. }]);