JSFiddle - React, Tailwind, and code Playground
HTML
<!--Container-->
<div id="container">
<ul id="tabs"><li id="tabAdd">+</li></ul>
</div>
<!--Popup window-->
<div id="popup">
<span href="#" id="x__popup"></span>
<form id="form">
Tab name: <input type="text" name="input" value="" maxlength="8" placeholder="Up to 8 characters" id="inputName">
<a href="#" id="form__ok">Ok</a>
<a href="#" id="form__cancel">Cancel</a>
</form>
</div>
<!--Popup background-->
<div id="popup__bgr"></div>
CSS
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, figure,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
background: transparent;
vertical-align: baseline;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
:focus {
outline: 0;
}
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*, *:before, *:after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
/*Reset above*/
@import url(http://fonts.googleapis.com/css?family=Titillium+Web);
/*Main container*/
#container {
background-color: #2c3e50;
font-size: 0;
margin: 150px auto;
height: 400px;
}
/*Tabs*/
.item {
background-color: #f1c40f;
font-size: 14px;
display: inline-block;
text-align: center;
width: 100px;
height: 40px;
position: relative;
vertical-align: top;
line-height: 46px;
border-left: 1px solid red;
text-transform: lowercase;
}
.item:hover {
background-color: #d35400;
}
/*Add a tab*/
#tabAdd {
color: #fff;
width: 40px;
height: 40px;
position: relative;
display: inline-block;
font-size: 35px;
background-color: #d35400;
vertical-align: top;
text-align: center;
margin-right: 3px;
}
#tabAdd:hover {
background-color: #e98b39;
color: #2c3e50;
cursor:pointer;
}
.close {
position: absolute;
top: 3px;
left: 78px;
height: 20px;
width: 20px;
line-height:20px;
cursor: pointer;
font-size: 12px;
opacity: .6;
}
/*Popup window*/
#popup {
width: 300px;
height: 200px;
border-radius: 5px;
border: 3px #000 solid;
background: #fff;
position: fixed; /* чтoбы oкнo былo в...
JavaScript
$( document ).ready( function() {
/********** Click New tab *******/
$("#tabAdd").click( function(){
$( "#popup__bgr" ).fadeIn( 300,
function(){
$( "#popup" )
.css( "display", "block" )
.animate({ opacity: 1, top: '50%' }, 200)
});
$( function(){
$( "#inputName").val("");
});
});
/*********** Click Ok ************/
$( "#form__ok" ).click( function(){
var $name = $( "#inputName" ).val();
if( $name == "" ){
alert( "Please, gimme a name" );
return false;
};
var newTab = $( "<li class='item'></li>" );
newTab.text( $name );
newTab.insertBefore( "#tabAdd" ).hide().fadeIn( 600 );
var $span = $( "<span class='close'>✖</span>" );
$span.appendTo( newTab );
/*********Remove a tab******/
$( ".close" ).click( function(){
$( this ).closest( "li" ).fadeOut( 200, function() {$( this ).remove();});
});
$( "#popup__bgr" )
.animate({ opacity: 0, top: '45%' }, 200,
function(){
$( "#popup" ).css( "display", "none" );
$( "#popup__bgr" ).fadeOut( 200 );
$( "#popup__bgr" ).removeAttr('style');//REMOVE STYLES OF THE POPUP BACKGROUND!
}
);
})
/********Click Cancel / Background or Close **********/
$( "#x__popup, #popup__bgr, #form__cancel" ).click( function(){
$( "#popup__bgr" )
.animate({ opacity: 0, top: '45%' }, 200,
function(){
$( "#popup" ).css( "display", "none" );
$( "#popup__bgr" ).fadeOut( 200 ).removeAttr('style');//REMOVE STYLES OF THE POPUP BACKGROUND!
}
);
});
});