JSFiddle - React, Tailwind, and code Playground

by DannyEnglander

HTML

<div class="slider" id="slider"></div>

<div class="centerification">
    <a class="button" id="button" href="somestuffhere">Click To Slide Down</a>
</div>

CSS

.slider {
    height: 70px;
    width: 100%;
    display: none;
    background: blue;
}

.centerification {
    text-align: center;
}

.button {
    display: inline-block;
    margin-top: 10px;
    padding: 10px;
    text-decoration: none;
    font-family: sans-serif;
    color: rgba(30, 30, 30, 1);
    background: rgba(230, 230, 230, 1);
    border-radius: 5px;
    -webkit-box-shadow: 2px 2px 3px rgba(50,50,50,0.5); 
       -moz-box-shadow: 2px 2px 3px rgba(50,50,50,0.5);
            box-shadow: 2px 2px 3px rgba(50,50,50,0.5);
}

JavaScript

var is_down = false;

// switches is_down's boolean
function set_slider_property() {
    if (is_down) {
        is_down = false;
    } else {
        is_down = true;
    }
}

$('#button').on("click", function (e) {
    e.preventDefault();
    if (!is_down) {
        $('#slider').slideDown();
        setTimeout(set_slider_property, 1);
    }
    // no need for if (is_down) as the $(window) click function will handle that
});

$(window).on("click", function () {
    if (is_down) {
        $('#slider').slideUp();
        set_slider_property();
    }
});