- var cards = 10
h4 All Clean
.container
- for(var i = 0; i < cards; i++)
.card
.title Card #{i + 1}
.body Swipe me left or right to clear me from the stack
.actions
//- .left.action left
//- .right.action right
View Compiled
.container {
height: 100vh;
width: 100vw;
justify-content: center;
align-items: center;
display: grid;
grid-template-areas: 'center';
}
.card {
cursor: move;
grid-area: center;
width: 500px;
height: 300px;
max-width: 80vw;
max-height: 50vh;
background: #efefef;
border-radius: .7em;
box-shadow: 5px 5px 15px rgba(174, 126, 186, 0.5);
transform-origin: 50% 50%;
transition: 100ms all;
display: flex;
flex-direction: column;
.title {
border-radius: .7em .7em 0 0;
padding: 1em;
font-weight: 600;
text-transform: uppercase;
font-weight: 100;
color: #5e5e5e;
background: #f7cfe0;
letter-spacing: 1px;
}
.body {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
padding: 1em;
font-size: 1.2em;
color: #4E4E4E;
img {
object-fit: cover;
width: 100%;
height: 100%;
}
}
.actions {
display: flex;
.action {
cursor: pointer;
background: hsla(300, 100%, 25%, 0.05);
height: 40px;
flex: 1;
display: flex;
justify-content: center;
align-items: center;
margin: .5em;
}
}
opacity: 0;
&:nth-of-type(1) {
opacity: 1;
z-index: 3;
}
&:nth-of-type(2) {
opacity: 1;
z-index: 2;
transform: translateY(30px) scale(.9);
}
&:nth-of-type(3) {
opacity: 1;
z-index: 1;
transform: translateY(60px) scale(.8);
}
&:nth-of-type(4) {
opacity: 1;
z-index: 0;
transform: translateY(90px) scale(.7);
}
&:nth-of-type(5) {
opacity: 1;
z-index: -1;
transform: translateY(120px) scale(.6);
}
&:nth-of-type(6) {
opacity: 1;
z-index: -2;
transform: translateY(150px) scale(.5);
}
&:nth-of-type(7) {
opacity: 1;
z-index: -3;
transform: translateY(180px) scale(.4);
}
&:nth-of-type(8) {
opacity: 1;
z-index: -4;
transform: translateY(205px) scale(.3);
}
&:nth-of-type(9) {
opacity: 1;
z-index: -5;
transform: translateY(228px) scale(.2);
}
&:nth-of-type(10) {
opacity: 1;
z-index: -6;
transform: translateY(240px) scale(.1);
}
}
@import url('https://fonts.googleapis.com/css?family=Lato:300,400,700');
body {
background: #ccc9e0;
font-family: 'Lato', sans-serif;
overflow: hidden;
}
h4 {
position: fixed;
left: 50%;
transform: translateX(-50%);
top: 50%;
}
View Compiled
const cards = document.getElementsByClassName("card");
for (let card of cards) {
var hammertime = new Hammer(card);
hammertime.on("swipe", function(ev) {
let xStart = ev.deltaX;
let yStart = ev.deltaY;
let xi = 0;
let yi = 0;
let opacityFramesOriginal = 200;
let opacityFrames = 200;
var framesReq;
function swipeOut() {
const str = `translateX(${xStart + xi}px) translateY(${yStart + yi}px)`;
card.style.transform = str;
card.style.opacity = 1 / opacityFrames;
if (xStart < 0) {
xi--;
} else {
xi++;
}
if (yStart < 0) {
yi--;
} else {
yi++;
}
opacityFrames--;
framesReq = requestAnimationFrame(swipeOut);
if (opacityFrames < opacityFramesOriginal - 10) {
cancelAnimationFrame(framesReq);
card.parentNode.removeChild(card);
}
}
swipeOut();
});
hammertime.on("pan", function(ev) {
const x = ev.deltaX;
const y = ev.deltaY;
const str = `translateX(${x}px) translateY(${y}px)`;
card.style.transform = str;
});
hammertime.on("panend", function(ev) {
card.style.transform = "";
});
}
This Pen doesn't use any external CSS resources.