Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="transition-components-demo" class="demo">
  
  <div class="btn-group-wrap">
    <div class="btn-group">
      <div 
           v-for="(slide, index) in slides" 
           type="button" @click="currentIndex = index" 
           :class="['btn', { 'btn-primary': index === currentIndex, 'btn-default': index !== currentIndex }]"
           >
             
      </div>
    </div>
    
    <transition name="fade"> 
      <div v-if="slideLeft" class="btn-previous-wrap">
        <div @input="gotToPrev()" @click="gotToPrev()" class="btn-previous"></div>
      </div>
    </transition>
    
    <transition name="fade">
      <div v-if="slideRight" class="btn-next-wrap">
        <div @input="gotToNext()" @click="gotToNext()" class="btn-next"></div>
      </div>
    </transition> 
    
  </div> 

<div class="swipe-element">
  <div class="swipe-front">
    <transition
      v-on:enter="enter"
      v-on:after-enter="afterEnter"					
      v-on:leave="leave"
      v-bind:css="false"
     >
      <slide :data="slides[currentIndex]" :key="currentIndex" class="current-slide">
      </slide>
    </transition>
  </div>
</div>
  
  
</div>

              
            
!

CSS

              
                body
{
    position: fixed;

    overflow: scroll;

    width: 100%;
    height: 100%;
    margin: 0 auto;
    padding: 0 auto;

    background-color: #090e38;
}


.current-slide
{
    position: absolute;

    width: 100vw;
    height: 100vh;
    margin-top: 0;
    padding: 0;

    background-color: #553890;
}

.current-slide p
{
    font-family: Sans-serif;
    font-size: 2em;

    position: absolute;
    top: 50%;
    left: 50%;

    margin: 0 auto;

    transform: translateY(-50%) translateX(-50%);
    text-align: center;

    color: #fff;
}


.btn
{
    display: inline-block;

    width: 25px;
    height: 25px;
    margin-right: 15px;

    transition: all .5s ease;

    border: solid 1px  #2f1b4e;
    border-radius: 50%;
    outline: none !important;
}


.btn:nth-last-child(1)
{
    margin-right: 0;
}

.btn.btn-primary
{
    border: solid 1px red;
    outline: none;
    background-color: rgb(160,92,255);
    background-color: rgba(160,92,255,.4);
}

.btn.btn-primary:hover
{
    color: #fff;
    border: solid 1px red;
    background-color: #4e2d80;
}

.btn.btn-primary:active,
.btn.btn-primary:focus
{
    color: #fff;
    border: solid 1px red;
    background-color: rgb(160,92,255);
    background-color: rgba(160,92,255,.4);
}


.btn.btn-default
{
    opacity: .7;
}


.btn.btn-default:hover
{
    opacity: 1;
    color: #fff;
    border: solid 1px red;
    background-color: #4b3080;
}

.btn.btn-default:active,
.btn.btn-default:focus
{
    color: #fff;
    background-color: #a05cff;
    background-color: rgb(160,92,255);
    background-color: rgba(160,92,255,.7);
}


.btn-group-wrap
{
    position: fixed;
    z-index: 999;
    bottom: 5%;

    width: 100%;
    height: 25px;
}

.btn-group
{
    position: absolute;
    top: 50%;
    left: 50%;

    transform: translateY(-50%) translateX(-50%);
}

/* Active animation */
.active-animation
{
    position: absolute;
    top: 30px;
    left: 50%;

    transform: translate(-50%, 0);
}

.btn-previous-wrap {
    position: fixed;
    opacity: .07;
    top: 40vh;
    left:25px;
    height: 20vh;
    width: 35px;
    transition: opacity .3s ease;
}

.btn-previous-wrap:hover
{
    opacity: 1;
}

.btn-previous
{
    position: absolute;

    width: 0;
    height: 0;

    opacity: 1;
    border-top: 10vh solid transparent;
    border-right: 35px solid black;
    border-bottom: 10vh solid transparent;
  
    transition: border-right .3s ease;
}

.btn-previous:hover
{
    opacity: 1;
    border-right: 35px solid #7343bc;
}

.btn-next-wrap {
    position: fixed;
    opacity: .07;
    top: 40vh;
    right: 25px;
    height: 20vh;
    width: 35px;
    transition: opacity .3s ease;
}

.btn-next-wrap:hover
{
    opacity: 1;
}

.btn-next
{
    position: absolute;
    top: 0;
    right: 0;

    width: 0;
    height: 0;
   
    opacity: 1;
    border-top: 10vh solid transparent;
    border-bottom: 10vh solid transparent;
    border-left: 35px solid black;
    
    transition: border-left .3s ease;
}

.btn-next:hover
{
    opacity: 1;
    border-left: 35px solid #7343bc;
}


/* Could Use GSAP here as well */
/* Vue JS - Transition Classes */
/* fade in or out - Previous and Next Buttons */

.fade-enter
{
    opacity: 0;
}

.fade-enter-active
{
    transition: opacity 4s ease;
}

.fade-enter-to
{
    /* Vue JS Default is opacity: 1; */
}

.fade-leave
{
    /* Vue JS Default is opacity: 1; */
}

.fade-leave-active
{
    transition: opacity 4s ease;
}

.fade-leave-to
{
    opacity: 0;
}


/* Swipe Elements */
.swipe-front {
  width: 100%;
  height: 100%;
  /*border: solid 1px red;*/
  -ms-touch-action: none;
  /* // [START touch-action-example] */
  /* Pass all touches to javascript */
  touch-action: none;
  /* // [END touch-action-example] */

  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}

.swipe-element {
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                Vue.component('slide', {
  template: '<div v-html="data.content"></div>',
  props: {
    data: {
      required: true,
      type: Object
    }
  }
});

new Vue({
  el: '#transition-components-demo',
  data() {
    return {
      slides: [
        {
          content: '<p>Slide 1</p>'
        },
        {
          content: '<p>Slide 2</p>'
        },
        {
          content: '<p>Slide 3</p>'
        },
        {
          content: '<p>Slide 4</p>'
        }
      ],
      currentIndex: 0,
      imagesource:             'default',
      swipeRevealItems:        [],
      swipeRevealItemElements: [],
      swipeFrontElement:       [],
      swipeFronts:             [],
    } 
  },
  computed: {
    slideLeft() {
        if ( this.currentIndex === 0 ) {
          return false;
        } else {
          return true;
        }

      },
     
    slideRight() {
        if ( this.currentIndex === this.slides.length - 1 ) {
          return false;
        } else {
          return true;
        }
    },

    
  },
  mounted() {
    const self = this;

    /* *******************************************************
                        Swipe Gesture
    ******************************************************* */

    // Shim for requestAnimationFrame from Paul Irishpaul ir
    // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
    window.requestAnimFrame = (function(){
      'use strict';

      return window.requestAnimationFrame ||
                window.webkitRequestAnimationFrame ||
                window.mozRequestAnimationFrame ||
                function( callback ){
                  window.setTimeout(callback, 1000 / 60);
                };
    })();

    /* // [START pointereventsupport] */
    // eslint-disable-next-line
    var pointerDownName = 'pointerdown';
    // eslint-disable-next-line
    var pointerUpName = 'pointerup';
    // eslint-disable-next-line
    var pointerMoveName = 'pointermove';

    if (window.navigator.msPointerEnabled) {
      pointerDownName = 'MSPointerDown';
      pointerUpName = 'MSPointerUp';
      pointerMoveName = 'MSPointerMove';
    }

    // Simple way to check if some form of pointerevents is enabled or not
    window.PointerEventsSupport = false;
    if (window.PointerEvent || window.navigator.msPointerEnabled) {
      window.PointerEventsSupport = true;
    }
    /* // [END pointereventsupport] */


    function SwipeRevealItem(element) {
      'use strict';

      // Gloabl state variables
      var swipeFrontElementLocal = element.querySelector('.swipe-front');
      this.swipeFrontElement = swipeFrontElementLocal;
      var swipeFrontElement = this.swipeFrontElement;
      var rafPending = false;
      var initialTouchPos = null;
      var lastTouchPos = null;
      var currentXPosition = 0;


      // Perform client width here as this can be expensive and doens't
      // change until window.onresize
      var itemWidth = swipeFrontElement.clientWidth;
      var slopValue = itemWidth * (1/4);

      // On resize, change the slop value
      this.resize = function() {
        itemWidth = swipeFrontElement.clientWidth;
        slopValue = itemWidth * (1/4);
      };

      /* // [START handle-start-gesture] */
      // Handle the start of gestures
      this.handleGestureStart = function(evt) {
        evt.preventDefault();
        evt.stopPropagation();

        if (evt.touches && evt.touches.length > 1) {
          return;
        }

        // Add the move and end listeners
        if (window.PointerEvent) {
          evt.target.setPointerCapture(evt.pointerId);
        } else {
          // Add Mouse Listeners
          document.addEventListener('mousemove', this.handleGestureMove, true);
          document.addEventListener('mouseup', this.handleGestureEnd, true);
        }

        initialTouchPos = getGesturePointFromEvent(evt);

        // swipeFrontElement.style.transition = 'initial';
      }.bind(this);
      /* // [END handle-start-gesture] */

      

      // Handle move gestures
      //
      /* // [START handle-move] */
      this.handleGestureMove = function(evt) {
        evt.preventDefault();
        evt.stopPropagation();

        if (!initialTouchPos) {
          return;
        }

        lastTouchPos = getGesturePointFromEvent(evt);

        if (rafPending) {
          return;
        }

        rafPending = true;

        window.requestAnimFrame(onAnimFrame);
      }.bind(this);
      /* // [END handle-move] */

      /* // [START handle-end-gesture] */
      // Handle end gestures
      this.handleGestureEnd = function(evt) {

        evt.preventDefault();
        evt.stopPropagation();

        if (evt.touches && evt.touches.length > 0) {
          return;
        }

        rafPending = false;

        // Remove Event Listeners
        if (window.PointerEvent) {

          evt.target.releasePointerCapture(evt.pointerId);

        } else {
          // Remove Mouse Listeners
          document.removeEventListener('mousemove', this.handleGestureMove, true);
          document.removeEventListener('mouseup', this.handleGestureEnd, true);
        }

        updateSwipeRestPosition();

        initialTouchPos = null;
      }.bind(this);
      /* // [END handle-end-gesture] */

      function updateSwipeRestPosition() {

        if (initialTouchPos === null) {
          initialTouchPos = 0;
        }

        if (lastTouchPos === null) {
          lastTouchPos = 0;
        }

        var differenceInX = initialTouchPos.x - lastTouchPos.x;
        if (differenceInX === null) {
          differenceInX = 0;
        }

        currentXPosition = currentXPosition - differenceInX;
        if (currentXPosition === null) {
          currentXPosition = 0;
        }

        // Check if we need to change state to left or right based on slop value
        if (Math.abs(differenceInX) > slopValue) {
          if (differenceInX > 0) {
            // self.goToNext();
            if ( self.currentIndex === self.slides.length - 1 ) {
              return
            } else {
              self.currentIndex++;
            }
          } else {
            // self.goToPrev();
            if ( self.currentIndex === 0 ) {
              return
            } else {
              self.currentIndex--;
            }
          } // END else
        } // END IF

      } // END updateSwipeRestPosition


      function getGesturePointFromEvent(evt) {
        var point = {};

        if (evt.targetTouches) {
          point.x = evt.targetTouches[0].clientX;
          point.y = evt.targetTouches[0].clientY;
        } else {
          // Either Mouse event or Pointer Event
          point.x = evt.clientX;
          point.y = evt.clientY;
        }

        return point;
      } // END getGesturePointFromEvent

      function onAnimFrame() {
        if (!rafPending) {
          return;
        }

        rafPending = false;
      } // END onAnimFrame

      /* // [START addlisteners] */
      // Check if pointer events are supported.
      if (window.PointerEvent) {
        // Add Pointer Event Listener
        swipeFrontElement.addEventListener('pointerdown', this.handleGestureStart, true);
        swipeFrontElement.addEventListener('pointermove', this.handleGestureMove, true);
        swipeFrontElement.addEventListener('pointerup', this.handleGestureEnd, true);
        swipeFrontElement.addEventListener('pointercancel', this.handleGestureEnd, true);
      } else {
        // Add Touch Listener
        swipeFrontElement.addEventListener('touchstart', this.handleGestureStart, true);
        swipeFrontElement.addEventListener('touchmove', this.handleGestureMove, true);
        swipeFrontElement.addEventListener('touchend', this.handleGestureEnd, true);
        swipeFrontElement.addEventListener('touchcancel', this.handleGestureEnd, true);

        // Add Mouse Listener
        swipeFrontElement.addEventListener('mousedown', this.handleGestureStart, true);
      }
      /* // [END addlisteners] */
    } // END SwipeRevealItem


    function bindGestureNow() {
      'use strict';

      var swipeRevealItemElementsLocal = document.querySelectorAll('.swipe-element');
      self.swipeRevealItemElements = swipeRevealItemElementsLocal;

      for (var i = 0; i < self.swipeRevealItemElements.length; i++) {
        self.swipeRevealItems.push(new SwipeRevealItem(self.swipeRevealItemElements[i]));
      }

      // We do this so :active pseudo classes are applied.
      window.onload = function(){
        if (/iP(hone|ad)/.test(window.navigator.userAgent)) {
          document.body.addEventListener('touchstart', function() {}, false);
        }
      }; //END mobileBindGestue
    } // END bindGestureNow


    window.onresize = function () {
      'use strict';
      for (var i = 0; i < self.swipeRevealItems.length; i++) {
        self.swipeRevealItems[i].resize();
      }
    };

    var registerInteraction = function () {
      'use strict';
      return;
    };


    // START Pageload check and bind gesture
    let stateCheck = setInterval(() => {
      if (document.readyState === 'complete') {
        clearInterval(stateCheck);
        // document ready
        // emit the call to bindGesture function
        bindGestureNow();
      }
    }, 300); // END Pageload check and bind gesture


    this.swipeFronts = document.querySelectorAll('.swipe-front');

    for (var i = 0; i < this.swipeFronts.length; i++) {
      this.swipeFronts[i].addEventListener('touchstart', registerInteraction);
    }
    
  },

  created() {
    // Global Key Press Listener - For Previous and Next Buttons
    // Since these buttons are not part of a form with an Input Field
    // they do not have focus.
    // Using Vue's @keyup or @keyup.native did not work.
    // Vue forums and Laracst talk about a global listener to solve this 
    window.addEventListener('keyup', this.listenForArrowKeys);
  }, // END Mounted

  created() {
    // Global Key Press Listener - For Previous and Next Buttons
    // Since these buttons are not part of a form with an Input Field
    // they do not have focus.
    // Using Vue's @keyup or @keyup.native did not work.
    // Vue forums and Laracst talk about a global listener to solve this 
    window.addEventListener('keyup', this.listenForArrowKeys);
  },
  methods: {
    
    gotToPrev() {
      if ( this.currentIndex === 0 ) {
        return
      } else {
        this.currentIndex--;
      }
    }, // END gotToPrev
    
    gotToNext() {
      if ( this.currentIndex === this.slides.length - 1 ) {
        return
      } else {
        this.currentIndex++;
      }
    }, // END gotToNext
    
    listenForArrowKeys (event) {  
        // If left or right arrow was pressed.
        if (event.keyCode == 37) { 
          console.log('left-arrow-pressed');
          // gotToPrevSlide;
          this.gotToPrev();
        } else if (event.keyCode == 39) { 
          console.log('right-arrow-pressed');
          // gotToNextSlide;
          this.gotToNext();
        } else {
          return   
        } 
      
    }, // END listenForArrowKeys
    
    
    enter(el, done) {
			const tl = new TimelineMax({
				onComplete: done
			})
			
			tl.set(el, {
				x: window.innerWidth * 1.5,
				scale: 0.7,
				transformOrigin: '50% 50%'
			})
			
			tl.to(el, 0.5, {
				x: 0,
				ease: Power4.easeOut
			});
			
			tl.to(el, 1, {
				scale: 1,
				ease: Power4.easeOut
			});
		},
		afterEnter() {
			
		},
		leave(el, done) {
			TweenMax.fromTo(el, 1, {
				autoAlpha: 1
			}, {
				autoAlpha: 0,
				ease: Power4.easeOut,
				onComplete: done
			});
		}
    
  }, // END methods
})
              
            
!
999px

Console