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

              
                <div class="container">
  <a data-modal="modal-one">Open Modal</a>
</div>

<div class="modal" id="modal-one">
  <div class="modal-bg modal-exit"></div>
  <div class="modal-container">
    <figure class="modal-img" style="">
  <img src='https://picsum.photos/800/800' alt='image'/>
  <img src='https://picsum.photos/800/900' alt='image'/>
  <img src='https://picsum.photos/800/700' alt='image'/>
  </figure>
    <button class="modal-close modal-exit">X</button>
  </div>
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
}
.container {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100vh;
  a {
    padding: 30px;
    background: teal;
    color: #fff;
    font-weight: bold;
    font-size: 24px;
    border-radius: 10px;
    cursor: pointer;
  }
}
.modal {
  position: fixed;
  // width: 100vw;
  // height: 100vh;
  // opacity: 0;
  // visibility: hidden;
  // transition: all 0.3s ease; // ! bewary about using transtions when working with GSAP 
  opacity: 0.5; // Show the button
  top: 0;
  // right: 0;
  // bottom: 0;
  left: 0;

  &.open {
    // visibility: visible;
    // opacity: 1;
    // transition-delay: 0s;
    opacity: 1;
  }
  &-bg {
    position: absolute;
    background: teal;
    width: 100%;
    height: 100%;
  }
  &-container {
    border-radius: 10px;
    background: #fff;
    position: relative;
    padding: 30px;
    width: 800px;
    margin: 0 auto;
  }
  &-close {
    position: absolute;
    right: 15px;
    top: 15px;
    outline: none;
    appearance: none;
    color: red;
    background: none;
    border: 0px;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.5;
  }
}

.modal-img {
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  aspect-ratio: 452 / 579; max-width: 500px;
  
  img{
  position: absolute;
  object-fit: cover;
  height:100%;
  width:100%; 
  top:0; 
}
}
              
            
!

JS

              
                

// // function animateStackingImages() {
//   var rotating_imgs = gsap.utils.toArray('.modal-img')
//     rotating_imgs.forEach((rotating_img) => {
      var timeline = gsap.timeline({
        repeat: -1,
        paused: true,
      })

      var targets = document.querySelectorAll('img')
      var numberOfTargets = targets.length

      var duration = 0.5 //change this
      var pause = 0.5 // change this

      var stagger = duration + pause
      var repeatDelay = stagger * (numberOfTargets - 1) + pause

      timeline
        .from(targets, {
          duration: duration,
          stagger: {
            each: stagger,
            repeat: -1,
            onRepeat: setZIndex(1),
            repeatDelay: repeatDelay,
          },
        })
        .to(
          targets,
          {
            duration: duration,
            stagger: {
              each: stagger,
              repeat: -1,
              onRepeat: setZIndex(0),
              repeatDelay: repeatDelay,
            },
          },
          stagger
        )
    // })

    function setZIndex(value) {
      return function () {
        this.targets()[0].style.zIndex = value
      }
    } 
// }

const modals = document.querySelectorAll("[data-modal]");

modals.forEach(function (trigger) {
  trigger.addEventListener("click", function (event) {
    event.preventDefault();
    const modal = document.getElementById(trigger.dataset.modal);
    timeline.restart();
    modal.classList.add("open");
    const exits = modal.querySelectorAll(".modal-exit");
    exits.forEach(function (exit) {
      exit.addEventListener("click", function (event) {
        event.preventDefault();
        modal.classList.remove("open");
        timeline.pause();
      });
    });
  });
});


// Start animation only if modal has 'is-open' class, else reverse animation from the beginning
// const modalOne = document.querySelector("modal");
// const isVisible = modalOne.classList.contains("is-open");

// if (isVisible) {
//   animateStackingImages()
// }
              
            
!
999px

Console