JSFiddle - React, Tailwind, and code Playground
by dimshik
HTML
<img src="https://s-media-cache-ak0.pinimg.com/originals/2f/29/6a/2f296afcd6980ebea5a40d17904fbe70.jpg" alt="" class="bg-image">
<div id="circle-shape-example">
<h1>KiwiFruit</h1>
<p>This is kiwifruit: originally called “yang tao”, “melonette” or Chinese gooseberry. Cultivated in its fuzzy variety from Chinese imports, the fruit proved popular with American military servicemen stationed in New Zealand during World War II, with commercial export to the United States starting after the end of the war. <span id="adPos"></span> In California, the fruit was rebranded as “kiwifruit” due to its resemblance to New Zealand’s national bird. However, it is not a “kiwi”, which is also the demonym for native New Zealanders. Saying “I’m going to eat a kiwi” implies that you are either a cannibal or planning to dine on an endangered flightless bird.</p>
</div>
<button id="insertBtn">Add Ad :)</button>
CSS
.bg-image {
position: absolute;
top:0;
left:0;
width:1000px;
}
#circle-shape-example {
position: absolute;
top: 145px;
left: 291px;
background-color: white;
transform: rotateZ(-20.8deg);
font-family: Open Sans, sans-serif;
margin: 2rem;
padding: 0.5rem;
width: 299px;
height: 541px;
overflow: hidden;
}
#circle-shape-example p {
line-height: 1.8;
}
#adPos {
position:relative;
}
#circle-shape-example .curve {
width: 0;
height: 0;
float: left;
margin-right:2rem;
border-radius: 50%;
-webkit-shape-outside:circle();
shape-outside:circle();
transition: width 0.7s;
}
.close-icon {
width:0px;
height:0px;
background: url("http://www.iop.org/IOP_Home/resources/images/close-icon.png") no-repeat 0 0;
position:absolute;
top: 20px;
right: 39px;
transition: all 0.1s;
cursor: pointer;
}
#insertBtn {
position:absolute;
top:10px;
left:10px;
}
JavaScript
var insertAd = function () {
var adPos = document.getElementById('adPos');
adPos.innerHTML = '<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/kiwifruit-on-a-plate.jpg" alt="A photograph of sliced kiwifruit on a while plate" class="curve"> <span class="close-icon"></span>';
adPos.style.display = 'inline';
window.setTimeout(function () {
var pic = document.querySelector('.curve');
pic.style.width = '70%';
pic.style.height = 'auto';
}, 50);
window.setTimeout(function () {
var icon = document.querySelector('.close-icon');
icon.style.width = '24px';
icon.style.height = '24px';
icon.addEventListener('click', removeAd);
}, 800);
}
var insertBtn = document.getElementById('insertBtn');
insertBtn.addEventListener('click', insertAd);
function removeAd() {
var icon = document.querySelector('.close-icon');
icon.style.width = '0px';
icon.style.height = '0px';
window.setTimeout(function () {
var pic = document.querySelector('.curve');
pic.style.width = '0px';
pic.style.height = 'auto';
}, 100);
window.setTimeout(function () {
document.getElementById('adPos').style.display = 'none';
}, 700);
}