Hide and Show Left and Right

In this example below you will see how to do a Hide and Show Left and Right with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 007design, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 007design ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Hide and Show Left and Right</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div data-ng-app="app">
  <div class="slideshow">
    <div class="slide" data-ng-class="{'hide-right': hideRight, 'hide-left': hideLeft, 'show-right': showRight, 'show-left': showLeft}" data-ng-show="showSlide">
      Hello
    </div>
    <div class="slide" data-ng-class="{'hide-right': hideRight, 'hide-left': hideLeft, 'show-right': showRight, 'show-left': showLeft}" data-ng-show="showSlide">
      World
    </div>
    <div class="slide" data-ng-class="{'hide-right': hideRight, 'hide-left': hideLeft, 'show-right': showRight, 'show-left': showLeft}" data-ng-show="showSlide">
      Goodbye
    </div>
    <div class="slide" data-ng-class="{'hide-right': hideRight, 'hide-left': hideLeft, 'show-right': showRight, 'show-left': showLeft}" data-ng-show="showSlide">
      Something else
    </div>
    <div class="buttons">
      <button data-ng-click="gotoSlide($index)" data-ng-repeat="button in slideSvc.slides">{{$index}}</button>
    </div>
  </div>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular-animate.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/007design/hide-and-show-left-and-right-XNKGvj */
.slideshow {
  position: relative;
  width: 100%;
  text-align: center;
  height: 100px;
}
.slideshow .slide {
  position: absolute;
  top: 50%;
  left: 50%;
  opacity: 1;
  transform: translate(-50%, -50%);
  transition: left linear 2s,opacity linear 2s;
}
.slideshow .slide.hide-left, .slideshow .slide.hide-right {
  display: none;
}
.slideshow .slide.hide-left-add, .slideshow .slide.hide-right-add {
  display: block;
}
.slideshow .slide.show-left-add {
  left: 100%;
}
.slideshow .slide.show-right-add {
  left: 0;
}
.slideshow .slide.hide-left-add-active {
  left: 0;
}
.slideshow .slide.hide-right-add-active {
  left: 100%;
}
.slideshow .slide.show-left-add-active, .slideshow .slide.show-right-add-active {
  left: 50%;
}

.gradient-one {
  background-color: red;
}

.gradient-two {
  background-color: blue;
}

.gradient-three {
  background-color: blue;
}

.gradient-four {
  background-color: orange;
}

.accordions .accordion-content {
  height: 50px;
  transition: all linear 0.5s;
  border: 1px solid red;
}
.accordions .accordion-content.ng-hide-add {
  height: 50px;
}
.accordions .accordion-content.ng-hide-add-active {
  height: 0;
}
.accordions .accordion-content.ng-hide-remove {
  height: 0;
}
.accordions .accordion-content.ng-hide-remove-active {
  height: 50px;
}


/*Downloaded from https://www.codeseek.co/007design/hide-and-show-left-and-right-XNKGvj */
angular.module('app', ['ngAnimate'])
.service('slideSvc', [function() {
  var scope = this;
  scope.slides = [];
  scope.activeSlide = 0;
  return scope;
}])
.directive('slideshow', ['$interval', '$timeout', 'slideSvc', function($interval, $timeout, slideSvc) {
  return {
    scope: true,
    restrict: 'C',
    link: function(scope, elem) {
      scope.slideSvc = slideSvc;
      var doSlide = function() {
        slideSvc.slides[slideSvc.activeSlide].showSlide = false;
        slideSvc.activeSlide += 1;
        if (slideSvc.activeSlide >= slideSvc.slides.length)
          slideSvc.activeSlide = 0;
        slideSvc.slides[slideSvc.activeSlide].showSlide = true;                
      };
      var interval;
      scope.start = function() {
        // interval = $interval(doSlide,3000);
      };
      scope.stop = function() {
        // $interval.cancel(interval);
      };
      
      scope.gotoSlide = function(i) {
        if (i === slideSvc.activeSlide) return;
        if (i < slideSvc.activeSlide) {
          slideSvc.slides[slideSvc.activeSlide].hideRight = true;
          slideSvc.slides[i].showRight = true;
        } else if (i > slideSvc.activeSlide) {
          slideSvc.slides[slideSvc.activeSlide].hideLeft = true;
          slideSvc.slides[i].showLeft = true;
        }
        slideSvc.slides[slideSvc.activeSlide].showSlide = false;
        slideSvc.activeSlide = i;
        slideSvc.slides[slideSvc.activeSlide].showSlide = true;
      };
      
      elem.on('mouseover', function() {
        scope.$apply(scope.stop);
      });
      elem.on('mouseout', function() {
        scope.$apply(scope.start);
      });
      // scope.start();
    }
  };
}])
.directive('slide', ['slideSvc', '$timeout', function(slideSvc, $timeout) {
  return {
    scope: true,
    restrict: 'C',
    link: function(scope, elem) {
      slideSvc.slides.push(scope);
            
      if (slideSvc.slides.length === 1)
        scope.showSlide = true;
      
      scope.$watch('showSlide', function(s) {
        $timeout(function() {
          scope.hideLeft = false;
          scope.hideRight = false;
          scope.showLeft = false;
          scope.showRight = false;
        },2000);
      });
    }
  };
}]);

Comments