JSFiddle - React, Tailwind, and code Playground

by David Thomas

HTML

<script src="https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js"></script>
<div class="container">
    <div class="news">
        <p>Lorem ipsum dolor sit amet...</p>
    </div>
    <div class="banner">
        <p>Yet more text, this time it's the banner.</p>
        <span class="close">X</span>
    </div>
</div>
<div id="clear">Remove the cookie</div>

CSS

.container {
    width: 80%;
    min-height: 400px;
    position: relative;
    border: 4px solid #000;
    overflow: hidden;
}
.news {
    width: 100%;
    height: 100%;
}

.banner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #f00;
}
.close {
    position: absolute;
    top: 0;
    right: 0;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    width: 2em;
    line-height: 2em;
    text-align: center;
    display: block;
    cursor: pointer;
}
#clear {
    width: 80%;
    text-align: right;
    color: #fff;
    background-color: #999;
    border: 4px solid #000;
    border-top-width: 0;
    font-family: arial, sans-serif;
    cursor: pointer;
}

JavaScript

$(document).ready(
    function(){
        if ($.cookie('closed')){
            $('.banner').remove();
        }
        $('.close').click(
            function(){
                $(this)
                    .closest('.banner')
                    .animate(
                        {
                            'top':'120%'
                        }, 1500,
                        function(){
                            $(this).remove();
                        }
                    );
                $.cookie('closed',true, {expires: 30});
            });
        $('#clear').click(
            function(){
                $.cookie('closed',false, {expires: -200});
            });
    });