Moving Underline

by Michael Mandarino

HTML

<a class="link-line">Hell World</a>





<div class="wrap">
    <div class="scroll-down">
        <div class="line" style=""></div>
        <div class="text">SCROLL</div>
    </div>
</div>

SCSS

a.link-line {
    cursor: pointer;
    font-size: 2rem;
    display: inline-block;
    position: relative;
    text-decoration: none;
    transition: all 0.2s ease-in-out;


    &::before {
        content: "";
        display: block;
        height: 2px;
        position: absolute;
        bottom: 0;
        right: 0;
        left: 0;
        background-color: #000;
        transform-origin: 0 50%;
        transition: transform 0.25s ease-in-out;
    }

    &:hover {
        &::before {
            transform: scaleX(0);
            transform-origin: 100% 50%;
            
        }
    }
}

.wrap {
    transform: rotate(90deg);
    position: fixed;
    right: 0;
    bottom: 0;

    .scroll-down {
        display: flex;
        align-items: center;
        font-size: 1.5rem;
        height: 50px;
        position: fixed;
        top: 50%;
        right: 50px;
        z-index: 100;

        .text {
            padding-left: 1rem;
        }

        .line {
            background-color: #000;
            display: block;
            height: 2px;
            transform-origin: 0 50%;
            transition: transform 0.5s ease-in-out;
            width: 50px;
        }

        &.animate,
        &:hover {
            .line {
                transform: scaleX(0);
                transform-origin: 100% 50%;
                transition-timing-function: ease;
            }
        }
    }
}

JavaScript

setInterval(function() {
    $('.scroll-down').addClass('animate');

    setTimeout(function() {
        $('.scroll-down').removeClass('animate');
    }, 1000);
}, 5000);