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

              
                <main class="main">

        <div class="cards">
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">1</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">2</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">3</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">4</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">5</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">6</div>
            </div>
            <div class="card card_js">
                <div class="card__contanet card-contanet_js">7</div>
            </div>

        </div>

    </main>
              
            
!

CSS

              
                .main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 200px 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 40px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  position: relative;
  display: flex;
  width: 100%;
  height: 300px;
  border: 1px solid gray;
  overflow: hidden;
}

.card__contanet {
    content: "";
    position: absolute;
    top: -100%;
    left: 0;

    display: flex;
    justify-content: center;
    align-items: center;

    width: 100%;
    height: 100%;

    background: #000;

    font-size: 40px;
    color: white;
}
              
            
!

JS

              
                  const cards = document.querySelector('.cards')
const cardsAnim = cards.querySelectorAll('.card_js')
    const cardsContentAnim = cards.querySelectorAll('.card-contanet_js')

    for (let index = 0; index < cardsAnim.length; index++) {
        const card = cardsAnim[index]
        const cardContent = cardsContentAnim[index]

        card.addEventListener('mouseenter', (mouse) => {
            closestEdge(mouse, card)
        })

        card.addEventListener('mouseleave', (mouse) => {
            closestEdgeLeave(mouse, card)
        })

        function closestEdge(mouse, elem) {
            let arrCord = funcCoord(mouse, elem)
            let min = Math.min(arrCord[0], arrCord[1], arrCord[2], arrCord[3])

            switch (min) {
                case arrCord[2]:
                     enterCard('left', '-100%', 'top', '0', 'left')
                     break
                case arrCord[3]:
                    return enterCard('left', '100%', 'top', '0', 'left')

                case arrCord[0]:
                     enterCard('left', '0', 'top', '-100%', 'top')
                     break
                case arrCord[1]:
                     enterCard('left', '0', 'top', '100%', 'top')
                      break
            }
        }

        function closestEdgeLeave(mouse, elem) {
            let arrCord = funcCoord(mouse, elem)
            let min = Math.min(arrCord[0], arrCord[1], arrCord[2], arrCord[3])

            switch (min) {
                case arrCord[2]:
                    leaveCard('left', '-100%')
                    break
                case arrCord[3]:
                     leaveCard('left', '100%')
                     break
                case arrCord[0]:
                     leaveCard('top', '-100%')
                     break
                case arrCord[1]:
                     leaveCard('top', '100%')
                break
            }
        }

        function funcCoord(ev, el) {
            let elemBounding = el.getBoundingClientRect()
            let elementLeftEdge = elemBounding.left
            let elementTopEdge = elemBounding.top
            let elementRightEdge = elemBounding.right
            let elementBottomEdge = elemBounding.bottom
            let mouseX = ev.pageX
            let mouseY = ev.pageY - getBodyScrollTop()
            let topEdgeDist = Math.abs(elementTopEdge - mouseY)
            let bottomEdgeDist = Math.abs(elementBottomEdge - mouseY)
            let leftEdgeDist = Math.abs(elementLeftEdge - mouseX)
            let rightEdgeDist = Math.abs(elementRightEdge - mouseX)

            return [topEdgeDist, bottomEdgeDist, leftEdgeDist, rightEdgeDist]
        }

        function enterCard(prop, num, prop1, num1, prop2) {
            cardContent.style[prop] = num
            cardContent.style[prop1] = num1
            cardContent.style.opacity = 0.5
            cardContent.style.transition = '0s all ease'

            setTimeout(() => {
                cardContent.style[prop2] = '0'
                cardContent.style.opacity = 1
                cardContent.style.transition = '0.3s all ease'
            }, 0)
        }

        function leaveCard(prop, num) {
            cardContent.style.top = '0'
            cardContent.style.left = '0'
            cardContent.style.opacity = 1
            cardContent.style.transition = '0s all ease'

            setTimeout(() => {
                cardContent.style[prop] = num
                cardContent.style.opacity = 0.5
                cardContent.style.transition = '0.3s all ease'
            }, 0)
        }
    }

    function getBodyScrollTop() {
        return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop)
    }
              
            
!
999px

Console