mainSlider.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. $scope.canIClick = false;
  22. $timeout(function(){
  23. $scope.canIClick = true;
  24. },3000)
  25. if($scope.currentSlide == $scope.slides.length - 1){
  26. $scope.currentSlide = 0;
  27. } else{
  28. $scope.currentSlide++;
  29. }
  30. },7000)
  31. }
  32. runInterval();
  33. $scope.selectImage = function(imageUrl){
  34. if($scope.canIClick){
  35. $scope.canIClick = false;
  36. $scope.currentSlide = $scope.slides.indexOf(imageUrl);
  37. $interval.cancel($scope.sliderInterval);
  38. runInterval();
  39. $timeout(function(){
  40. $scope.canIClick = true;
  41. },3000)
  42. }
  43. }
  44. }
  45. }
  46. }]);