JSFiddle - React, Tailwind, and code Playground
by mackry
HTML
<ul class="challenge-list">
<li class="challenge">Eat More Broccoli 1</li>
<li class="challenge">Eat More Broccoli 2</li>
<li class="challenge">Eat More Broccoli 3</li>
<li class="challenge">Eat More Broccoli 4</li>
</ul>
<div id="modal">
<div>
<h2>Eat More Broccoli 1</h2>
<a href="#close" title="Close">×</a>
</div>
<div>
<h2>Eat More Broccoli 2</h2>
<a href="#close" title="Close">×</a>
</div>
<div>
<h2>Eat More Broccoli 3</h2>
<a href="#close" title="Close">×</a>
</div>
<div>
<h2>Eat More Broccoli 4</h2>
<a href="#close" title="Close">×</a>
</div>
</div>
CSS
body {
background: #f7f7f7;
font-family: 'Helvetica Neue', Arial, sans-serif;
}
.challenge-list {
margin: 50px;
}
.challenge {
background: #fff;
border: 1px solid #ccc;
color: #555;
display: inline-block;
margin-right: 10px;
padding: 15px;
height: 100px;
width: 150px;
box-shadow: 0 1px 2px rgba(0, 0, 0, .07);
}
.challenge:hover {
border: 1px solid #999;
cursor: pointer;
}
.challenge.selected {
border-color: #00ABF7;
box-shadow: inset 2px 2px #00ABF7, inset -2px -2px #00ABF7;
}
#modal {
background-color: white;
background-color: rgba(0, 0, 0, 0);
display: block;
height: 0;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow-x: auto;
overflow-y: scroll;
z-index: 1;
-webkit-perspective: 1000;
}
#modal.show {
background-color: rgba(0, 0, 0, .15);
height: auto;
z-index: 9999;
-moz-transform: translateZ(0);
-webkit-transform: translateZ(0);
transform: translateZ(0);
-moz-transition: background 500ms ease-out 200ms;
-webkit-transition: background 500ms ease-out 200ms;
transition: background 500ms ease-out 200ms;
}
#modal div {
display: none;
z-index: 2;
}
#modal .active {
display: block;
position: absolute;
height: 100px;
width: 150px;
border: solid 1px #999;
padding: 15px;
opacity: 1;
background: white;
z-index: 3;
top: 0;
left: 0;
-moz-box-shadow: 0px 20px 60px rgba(0,0,0,.2);
-webkit-box-shadow: 0px 20px 60px rgba(0,0,0,.2);
box-shadow: 0px 20px 60px rgba(0,0,0,.2);
}
#modal.show .active {
height: 400px;
width: 350px;
overflow: hidden;
-moz-transition: all 200ms ease-out;
-webkit-transition: all 200ms ease-out;
transition: all 200ms ease-out;
}
#modal .before {
margin-left: -200px;
opacity: 0 !important;
}
#modal .after {
margin-left: 200px;
opacity: 0...
JavaScript
$(document).ready(function() {
var modal = $('#modal'),
dialogs = $('#modal div'),
close = modal.find('a[href="#close"]'),
challenges = $('.challenge'),
left = Math.round(($(window).width() / 2) - 190),
selectedChallenge = null,
activeDialog = null;
challenges.each(function() {
var $this = $(this);
$this.click(function() {
selectedChallenge = $this.addClass('selected');
activeDialog = dialogs.eq($this.index()).addClass('active');
var xPos = $this.offset().left,
yPos = $this.offset().top;
activeDialog.css(translate3d(xPos, yPos, 0));
setTimeout(function() {
modal.addClass('show');
activeDialog.css(translate3d(left, 200, 0));
}, 1);
});
});
modal.click(function(e) {
if ($(e.target).is('#modal')) {
closeModal();
}
});
close.click(closeModal);
function closeModal() {
selectedChallenge.removeClass('selected');
modal.removeClass('show');
dialogs.removeClass('active');
resetTransform(dialogs);
}
function resetTransform(el) {
el.css({
'-moz-transform': '',
'-webkit-transform': '',
'transform': ''
});
}
function translate3d(x, y, z) {
x = (x + 'px') || 0;
y = (y + 'px') || 0;
z = (z + 'px') || 0;
return {
'-moz-transform': 'translate3d(' + x + ', ' + y + ', ' + z + ')',
'-webkit-transform': 'translate3d(' + x + ', ' + y + ', ' + z + ')',
'transform': 'translate3d(' + x + ', ' + y + ', ' + z + ')'
};
}
// keyboard left right arrow keys
$(document).keydown(function(e) {
if (e.keyCode == 37) {
var prevChallenge = selectedChallenge.removeClass('selected').prev();
if (prevChallenge.is('li')) {
...