JSFiddle - React, Tailwind, and code Playground

by bgrins

HTML

<div class='container clearfix'>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
<p class='allow-blackout' style='float:left; width: 100px;'>
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.


</p>

<img class='allow-blackout' width=300 src='https://www.google.com/logos/2012/hertz-2011-hp.gif' />
    <br style='clear:both;' />
</div>

CSS

.container { position:relative; width: 95%; border: solid 1px; background: #eee; }

JavaScript

(function($) {
    
function unblackout() {
    
   $(".blackout").remove();
return false;
}
    function getBoxesForNode(parent, node) {
        
    var offset = $(node).position();
    var outerHeight = $(node).outerHeight(true);
    var outerWidth = $(node).outerWidth(true);
    
    var blockCSS = {
        position: "absolute"  ,
        background: "rgba(0, 0, 0, .8)"
    };
    
    var parentWidth = $(parent).width();
    var parentHeight = $(parent).height();
    
    var blockLeft = $("<div class ='blackout' />").css(blockCSS);
    var blockTop = $("<div class ='blackout' />").css(blockCSS);
    var blockRight = $("<div class ='blackout' />").css(blockCSS);
    var blockBottom = $("<div class ='blackout' />").css(blockCSS);
    
    
    
    blockLeft.width(offset.left).height(parentHeight).css({
        left: 0,
        top:0
    });
    
    
    blockTop.width(outerWidth).height(offset.top).css({
        left: offset.left,
        top: 0
    });
    
    blockRight.width(parentWidth - offset.left - outerWidth).height(parentHeight).css({
        left: offset.left + outerWidth,
        top: 0
    });
    
    
    blockBottom.width(outerWidth).height(parentHeight - offset.top - outerHeight).css({
        left: offset.left,
        top: offset.top + outerHeight
    });
        
        return [blockLeft, blockTop, blockRight, blockBottom];
        
    }
    
    $.fn.blackout = function() {
        var node = this[0];
        var container = node.ownerDocument.body;
        var boxes = getBoxesForNode(container, node);
        $(boxes).each(function() {
            $(container).append(this);
        })
                   return this;
    };
    
                   $(function() {

$(document).on("click", ".blackout", unblackout);
            });            
})(jQuery);

    
    
    
    
$(function() {
    $(document).on("click", ".allow-blackout", function() {
        $(this).blackout();
    });

    
});