Interactive Tailwind + Vue Responsive Navbar

by James Connolly

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<div id="app">
  <!--<div class="loadingScreen animated-75 delay-20 fadeOut"></div>-->
  <button @click="nextPage">prev page</button>
  <button @click="nextPage">next page</button>
  <button @click="closePage">X</button>
  <div class="test-block">
    <h1 :class="pageChange ? 'fadeOutRight': 'fadeInRight'" class="animated-30 delay-10">Sample Title</h1>
    <p :class="pageChange ? 'fadeOutRight': 'fadeInRight'" class="animated-30 delay-20">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
      Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus.</p>
  </div>
</div>

CSS

body {
  padding: 15px;
  font-family: 'arial', 'helvetica', sans-serif;
  position: relative;
}

h1,
p,
button {
  margin-bottom: 30px;
}

.loadingScreen{
  width: 100%;
  height: 100%;
  background: red;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 999;
  pointer-events: none;
}

/***** animations *****/

.animated-30 {
  -webkit-animation-duration: 0.3s;
  animation-duration: 0.3s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

.animated-75 {
  -webkit-animation-duration: 0.3s;
  animation-duration: 0.3s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

.delay-10 {
  animation-delay: 0.10s;
}

.delay-20 {
  animation-delay: 0.20s;
}

/*fadeOut*/

.fadeOut {
  -webkit-animation-name: fadeOut;
  animation-name: fadeOut;
}

@-webkit-keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/*fadeOutRight*/

.fadeOutRight {
  -webkit-animation-name: fadeOutRight;
  animation-name: fadeOutRight;
}

@-webkit-keyframes fadeOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(25px);
  }
}

@keyframes fadeOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(25px);
  }
}

/*fadeInRight*/

.fadeInRight {
  -webkit-animation-name: fadeInRight;
  animation-name: fadeInRight;
}

@-webkit-keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(-25px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(-25px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

JavaScript

new Vue({
  el: '#app',
  data: {
    pageChange: false,
    backToHome: false,
  },
  methods: {
    nextPage() {
      this.pageChange = !this.pageChange
    },
    closePage() {
      this.backToHome = !this.backToHome
    }
  }
})