Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                #app
    transition(name="carousel-fade" mode="out-in")
      .load-screen(v-if="loading" key="1")
        p Loading MCU Timeline

      .load-screen(v-else-if="!loading && error" key="2")
        p Timeline could not assemble
        
      main.main-screen(v-else key="3" :class="{ 'show-modal' : showModal }")
        carousel(v-if="movies.length" :class="scrollDirection" :options="carouselOptions" :movies="movies" :current="current" @scroll-direction="handleScrollDirection" @set-current="handleCurrentSlide" @trigger-modal="handleModal")

        transition(name="modal")
          modal(v-if="showModal" :id="movies[current].id" @trigger-modal="handleModal")

// Component templates
template#tpl__carousel
  .carousel
    .image__viewport
      transition(name="fade" mode="out-in")
        carousel-image.carousel__image(v-if="index === current" v-for="movie, index in movies" :backdrop="movie.backdrop_path" size="1280" :key="movie.id")

    embla(ref="embla" :options="options")
      carousel-item(v-for="movie in movies" :title="movie.title" :key="movie.id" v-on="$listeners")

    transition(name="fade")
      button.btn.btn--prev(v-if="canScrollPrev()" @click="scrollPrev")
        svg.icon--control(viewBox="0 0 24 24")
          path(d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z")

    transition(name="fade")
      button.btn.btn--next(v-if="canScrollNext()" @click="scrollNext")
        svg.icon--control(viewBox="0 0 24 24")
          path(d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z")
          
    .timeline
      .dot(v-for="movie, index in movies" :class="{ current : index === current }" @click="scrollTo(index)")
        .dot__image-wrapper
          carousel-image(:backdrop="movie.poster_path" size="154" :key="movie.id")

template#tpl__embla
  .carousel__viewport
    .carousel__container
      slot

template#tpl__carousel-item
  li.carousel__slide
    h2.slide__title {{ title }}
    button.btn.btn--cta(@click="handleModal")
      svg.icon--play(viewBox="0 0 24 24")
        path(d="M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M10,16.5L16,12L10,7.5V16.5Z")
      span Watch trailer

template#tpl__carousel-image
  img(:src="src")
  
template#tpl__modal
  .modal
    .modal__overlay(@click="handleModal")
    .modal__wrapper
      iframe(v-if="src" :src="src" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen)
      button.btn.btn--close(title="Close trailer window" @click="handleModal")
        svg.icon--close(viewBox="0 0 24 24")
          path(d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z")
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400&family=Playfair+Display:ital@1&display=swap');

:root {
  --font-primary: 'Oswald', sans-serif;
  --font-secondary: 'Playfair Display', serif;
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  --duration: 500ms;
  --backdrop-offset: 12px;
  --btn-size: calc(0.75rem + 5vmin);
  --btn-cta-font-size: min(max(14px, 3vw), 30px);
  --slide-title-font-size: min(max(16px, 4vw), 60px);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  background-color: black;
  font-family: var(--font-primary);
  overflow: hidden;
}

.load-screen {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(white, 0.4);
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.025rem;
  font-size: unquote("min(max(16px, 4vw), 60px)");
  transform: translate(-50%, -50%);
  
  p {
    opacity: 0;
    animation: fadein var(--duration) var(--duration) var(--ease-out) forwards;   
  }
  
  @keyframes fadein {
    to { opacity: 1 }
  }
}


// ===============================
// Carousel viewport
// ===============================

.carousel__viewport {  
  --mask-size: 6vw;
  
  position: relative;
  width: 100%;
  height: 100vh;
  z-index: 2;
  overflow: hidden;
  mask-image: linear-gradient(
    to right,
    transparent,
    transparent var(--mask-size),
    black calc(var(--mask-size) * 2),
    black calc(100% - calc(var(--mask-size) * 2)),
    transparent calc(100% - var(--mask-size)),
    transparent
  );
}

.carousel__viewport.is-draggable {
  cursor: move;
  cursor: grab;
}

.carousel__viewport.is-dragging {
  cursor: grabbing;
}

.carousel__container {
  display: flex;
  align-items: center;
  height: 100%;
  height: -webkit-fill-available;
}


// ===============================
// Carousel slide
// ===============================

.carousel__slide {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0 8vw;
  text-align: center;
  list-style: none;
  color: white;
  transform: translateY(var(--btn-cta-font-size)) scale(1.0001);
  transition: transform calc(var(--duration) / 2) var(--ease-out);
  
  &.is-selected {
    transform: translateY(0) scale(1.0001);
    transition-duration: calc(var(--duration) / 2);
    transition-delay: calc(var(--duration) * 1.25);
  }
}

.slide__title {
  font-size: var(--slide-title-font-size);
  line-height: 1.2;
  opacity: 0.6;
  text-transform: uppercase;
  transform: scale(0.98);
  transition: 
    opacity calc(var(--duration) * 1.5) var(--ease-out),
    transform var(--duration) var(--ease-out);
  
  .is-selected & {
    opacity: 1;
    transform: scale(1.18);
  }
}


// ===============================
// Image viewport
// ===============================

.image__viewport {
  --mask-size: 40px;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  z-index: 1;
  transform: scale(1.02);
  mask-image: linear-gradient(
    to bottom,
    transparent,
    transparent var(--mask-size),
    black calc(var(--mask-size) * 4),
    black calc(100% - calc(var(--mask-size) * 4)),
    transparent calc(100% - var(--mask-size)),
    transparent
  );
}

.carousel__image {
  position: absolute;
  top: calc(var(--backdrop-offset) / -2);
  left: calc(var(--backdrop-offset) / -2);
  width: calc(100% + var(--backdrop-offset));
  height: calc(100% + var(--backdrop-offset));
  z-index: 1;
  opacity: 0.5;
  object-fit: cover;
}


// ===============================
// Buttons
// ===============================

.btn {
  border: 0;
  padding: 0;
  outline: none;
  cursor: pointer;
  background-color: transparent;
  color: white;
  fill: currentcolor;
  z-index: 3;
  touch-action: manipulation;
}

.btn--cta {
  display: flex;
  align-items: center;
  margin-top: 1rem;
  font-family: var(--font-secondary);
  font-size: var(--btn-cta-font-size);
  font-style: italic;
  letter-spacing: 0.05rem;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  visibility: hidden;
  transition:
    transform 0s var(--duration) var(--ease-out),
    opacity calc(var(--duration) / 4) var(--ease-out),
    visibility 0s var(--duration);
  
  > * + * {
    margin-left: 0.25rem;
  }
  
  svg {
    margin-top: 0.125em;
    width: 1.25em;
    height: 1.25em;
    fill: currentcolor;
    transition: fill calc(var(--duration) / 4) var(--ease-out);
  }
  
  .is-selected & {
    opacity: 1;
    visibility: visible;
    pointer-events: initial;
    transform: translateY(0);
    transition-duration: calc(var(--duration) / 1.5);
    transition-delay: calc(var(--duration) * 1.5);
  }
}

.btn--prev,
.btn--next {
  position: absolute;
  top: calc(50% - (var(--btn-size) / 2));
}

.btn--prev {
  left: 12px;
}

.btn--next {
  right: 12px;
}

.btn .icon--control {
  width: var(--btn-size);
  height: var(--btn-size);
}

.btn--close {
  position: absolute;
  right: -8px;
  bottom: calc(100% + 1rem);
  width: var(--btn-size);
  height: var(--btn-size);
  opacity: 0;
  transition: opacity calc(var(--duration) / 4) var(--ease-out);
  
  .show-modal & {
    opacity: 1;
    transition-duration: calc(var(--duration) / 2);
  }
}


// ===============================
// Timeline
// ===============================

.timeline {
  --margin: 10vw;
  display: flex;
  justify-content: space-between;
  position: absolute;
  bottom: 4rem;
  margin: 0 var(--margin);
  width: calc(100% - (var(--margin) * 2));
  z-index: 3;
}

.dot {
  --line-size: 6px;
  --line-height: 40px;
  flex: 1 0 auto;
  display: flex;
  justify-content: space-between;
  position: relative;
  border-bottom: var(--line-size) solid white;
  height: var(--line-height);
  cursor: pointer;
  user-select: none;
  
  &::before {
    content: '';
    position: absolute;
    right: 1px;
    bottom: 4px;
    width: 1px;
    height: calc(var(--line-height) / 6);
    background-color: white;
  }
  
  &::after {
    content: '';
    position: absolute;
    top: calc(100% + var(--line-size));
    width: 100%;
    height: var(--line-height);
  }
  
  &:hover ~ .dot {
    opacity: 0.25;
  }
  
  :not(:hover) & {
    &.current:not(:hover) ~ .dot {
      opacity: 0.25;      
    }
  }
}
  
.dot__image-wrapper {
  --wrapper-size: 100px;
  position: absolute;
  bottom: 100%;
  right: calc((var(--wrapper-size) * -1) + (var(--line-size) / 2));
  width: var(--wrapper-size);
  height: auto;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity calc(var(--duration) * 2) var(--ease-out);
  
  &::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin: 0 auto;
    height: var(--line-height);
    width: var(--line-size);
    pointer-events: none;
    background-color: white;
    transform-origin: 50% 100%;
    opacity: 0;
  }
  
  img {
    width: 100%;
    opacity: 0;
    transition: opacity var(--duration) var(--ease-out),
  }
  
  .dot:hover & {
    opacity: 1;
    pointer-events: initial;
    transition-duration: calc(var(--duration) / 4);
    z-index: 1;
    
    img {
      opacity: 1;
      transition-duration: 0s;
    }
    
    &:after {
      opacity: 1;
    }
  }
}


// ===============================
// Modal
// ===============================

.modal {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 0;
  left: 0;
  padding: 4rem 4vw;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.modal__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.modal__wrapper {
  position: relative;
  width: 100vw;
  max-width: 1000px;
  margin: auto;
  background: black;
  
  &::after {
    content: "";
    display: block;
    padding-bottom: calc(100% / (16 / 9));
  }
  
  iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}


// ===============================
// Global transitions
// ===============================

.fade-enter-active {
  transition: 
    opacity var(--duration) var(--ease-out),
    transform var(--duration) var(--ease-out);
}

.fade-leave-active {
  transition: 
    opacity calc(var(--duration) / 2) var(--ease-in),
    transform calc(var(--duration) / 2) var(--ease-in);
}

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

.fade-enter {
  .scroll-prev & {
    transform: translateX(calc(var(--backdrop-offset) * -1));    
  }
  
  .scroll-next & {
    transform: translateX(var(--backdrop-offset));
  }
}

.fade-leave-to {
  .scroll-prev & {
    transform: translateX(var(--backdrop-offset));
  }
  
  .scroll-next & {
    transform: translateX(calc(var(--backdrop-offset) * -1));
  }
}

.carousel-fade-enter-active {
  transition: opacity calc(var(--duration) * 4) var(--duration) var(--ease-out);
}

.carousel-fade-leave-active {
  transition: opacity var(--duration) calc(var(--duration) * 3) var(--ease-out);
}

.carousel-fade-enter,
.carousel-fade-leave-to {
  opacity: 0;
}


// ===============================
// Modal transitions
// ===============================

.modal-enter-active {
  transition: opacity var(--duration) calc(var(--duration) / 3) var(--ease-out),
    transform var(--duration) calc(var(--duration) / 3) var(--ease-out);
  
  .btn--close {
    opacity: 0;
  }
}

.modal-leave-active {
  transition: 
    opacity calc(var(--duration) / 2) var(--ease-out),
    transform calc(var(--duration) / 2) var(--ease-out);
}

.modal-enter, .modal-leave-to {
  opacity: 0;
  transform: scale(1.04);
}

.carousel__viewport,
.image__viewport,
.timeline,
.btn--prev,
.btn--next {
  transition: 
    opacity var(--duration) calc(var(--duration) / 2) var(--ease-out),
    transform var(--duration) var(--ease-out);
  
  .show-modal & {
    transition-delay: 0s;
    transition-duration: var(--duration);
  }
}

.carousel__viewport {  
  .show-modal & {
    opacity: 0;
    transform: scale(0.9);
  }
}

.image__viewport {  
  .show-modal & {
    opacity: 0.75;
    transform: scale(1.0001);
  }
}

.timeline,
.btn--prev,
.btn--next {
  .show-modal & {
    opacity: 0;
    transform: scale(0.96);
    pointer-events: none;
  }
}

.image__viewport {
  transition: 
    opacity var(--duration) var(--ease-out),
    transform var(--duration) var(--ease-out),
    filter var(--duration) var(--ease-out);
  
  .show-modal & {
    filter: grayscale(100%);
  }
}
              
            
!

JS

              
                Vue.component("embla", {
  props: { options: Object },
  template: "#tpl__embla",
  
  methods: {
    init() {
      this.$embla = EmblaCarousel(this.$el, this.options);
    },
    
    api() {
      return this.$embla;
    }
  },
  
  mounted() {
    this.init();
  },
});

Vue.component("carousel", {
  props: { movies: Object, options: Object, current: Number },
  template: "#tpl__carousel",
  
  methods: {
    setCurrent() {
      this.$emit('set-current', this.$refs.embla.api().selectedScrollSnap());
    },
    
    setScrollDirection() {
      if (this.$refs.embla.api().selectedScrollSnap() > this.$refs.embla.api().previousScrollSnap()) {                
       return this.$emit('scroll-direction', 'scroll-next');
      }
      
      this.$emit('scroll-direction', 'scroll-prev');
    },
    
    scrollTo(target) {
      this.$refs.embla.api().scrollTo(target);
    },
    
    scrollPrev() {
      this.$refs.embla.api().scrollPrev();
    },
    
    scrollNext() {
      this.$refs.embla.api().scrollNext();
    },
    
    canScrollPrev() {
      return this.$refs.embla ? this.$refs.embla.api().canScrollPrev() : false;
    },
    
    canScrollNext() {
      return this.$refs.embla ? this.$refs.embla.api().canScrollNext() : true;
    },
    
    handleUpdate() {
      this.setCurrent();
      this.setScrollDirection();
    },
  },
  
  mounted() {
    this.$refs.embla.api().on('select', this.handleUpdate);
  }
});

Vue.component("carousel-item", {
  props: { title: String },
  template: "#tpl__carousel-item",
  
  methods: {
    handleModal() {
      this.$emit('trigger-modal');
    }
  }
});


Vue.component("carousel-image", {
  props: { backdrop: String, size: String },
  template: "#tpl__carousel-image",
  
  computed: {
    src() {
      return `https://image.tmdb.org/t/p/w${this.size}${this.backdrop}`;
    }
  }
});

Vue.component("modal", {
  props: { id: Number },
  template: "#tpl__modal",
  
  data() {
    return {
      src: null
    }
  },
  
  methods: {
    fetchVideo() {
      fetch(`https://api.themoviedb.org/3/movie/${this.id}/videos?api_key=${userKey}&language=en-US`)
        .then(res => res.json())
        .then(data => {
          setTimeout(() => {
            this.src = `https://www.youtube.com/embed/${data.results[0].key}?autoplay=1&mute=1`;
          }, 400);
        })
        .catch(err => err);
    },
    
    handleModal() {
      this.$emit('trigger-modal');
    }
  },
  
  mounted() {
    this.fetchVideo();
  }
});

const app = new Vue({
  el: "#app",
  
  data: {
    carouselOptions: { speed: 25 },
    current: 0,
    movies: [],
    scrollDirection: null,
    showModal: false,
    loading: true,
    error: false
  },
  
  methods: {
    handleScrollDirection(value) {
      this.scrollDirection = value;
    },
    
    handleCurrentSlide(value) {
      this.current = value;
    },
    
    handleModal() {
      this.showModal = !this.showModal;
    },
    
    fetchMovieList() { 
      this.loading = true;
      fetch(`https://api.themoviedb.org/3/list/142235?api_key=${userKey}&language=en-US`)
        .then(res => res.json())
        .then(data => this.movies = data.items)
        .then(this.loading = false)
        .catch(err => this.error);
    },
  },
  
  mounted() {
    this.fetchMovieList();
  }
});

              
            
!
999px

Console