<div class="demo">
<header class="demo__header"></header>
<div class="demo__content">
<div class="demo__card-cont">
<div class="demo__card result">
<p class="demo__card__we">You are among</p>
<p style="margin-top: 50%" class="demo__card__we counter-description"></p>
</div>
<div class="demo__card on-scroll-trigger-2 reject">
<div class="demo__card on-scroll-trigger-1 accept">
<div id="top_card" class="demo__card">
<div class="demo__card__top purple">
<div class="demo__card__img"></div>
<p class="demo__card__name">Spider pig</p>
</div>
<div class="demo__card__btm">
<p class="demo__card__we">Swipe left or right</p>
</div>
<div class="demo__card__choice m--reject on-scroll-trigger-2 reject-overlay"></div>
<div class="demo__card__choice m--like on-scroll-trigger-1 accept-overlay"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<main>
<div class="slide">
</div>
<div id="middle" class="slide">
<div class="scroll-trigger-1"></div>
<div class="scroll-trigger-2"></div>
</div>
<div class="slide">
</div>
</main>
*, *:before, *:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
font-size: 62.5%;
font-family: arial;
}
body {
background: #63BDF7;
transition: --scroll-position-delayed 0.15s linear;
--scroll-velocity: calc(var(--scroll-position) - var(--scroll-position-delayed));
--scroll-direction: sign(var(--scroll-velocity));
--scroll-speed: abs(var(--scroll-velocity));
}
main {
background: transparent;
z-index: 1;
scroll-snap-type: x mandatory;
}
@supports not (transform: scaleX(sign(-1))) {
body {
--scroll-speed: max(var(--scroll-velocity), -1 * var(--scroll-velocity));
--scroll-direction: calc(var(--scroll-velocity) / var(--scroll-speed));
}
}
$w: 30.6rem;
$h: 55rem;
$headerH: 6rem;
$cardW: 24rem;
$cardH: 32rem;
$cardTopH: 20.5rem;
$cardBtmH: $cardH - $cardTopH;
$imgSize: 12rem;
$purple: #7132B9;
$blue: #248CB6;
$indigo: #303F9F;
$cyan: #26C6DA;
$lime: #AFB42B;
$brown: #795548;
$orange: #FF945A;
$green: #B1DA96;
.demo {
position: fixed;
left: 50%;
top: 50%;
width: $w;
height: $h;
margin-left: $w/-2;
margin-top: $h/-2;
background: #F6F6F5;
box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.2);
&__header {
height: $headerH;
background: #002942;
}
&__content {
overflow: hidden;
position: relative;
height: $h - $headerH;
padding-top: 4.5rem;
user-select: none;
}
&__card-cont {
position: relative;
width: $cardW;
height: $cardH;
margin: 0 auto 5rem;
}
&__card {
z-index: 2;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
transform-origin: 50% 100%;
&.reset {
transition: transform 0.3s;
transform: translateX(0) !important;
.demo__card__choice {
transition: opacity 0.3s;
opacity: 0 !important;;
}
}
&.inactive {
transition: transform 0.3s;
}
&.to-left {
transform: translateX(-30rem) rotate(-30deg) !important;
}
&.to-right {
transform: translate(30rem) rotate(30deg) !important;
}
&.below {
z-index: 1;
}
&__top {
height: $cardTopH;
padding-top: 4rem;
&.purple {
background: $purple;
}
&.blue {
background: $blue;
}
&.indigo {
background: $indigo;
}
&.cyan {
background: $cyan;
}
&.lime {
background: $lime;
}
&.brown {
background: $brown;
}
}
&__img {
overflow: hidden;
width: $imgSize;
height: $imgSize;
margin: 0 auto 1.5rem;
border-radius: 50%;
border: 0.5rem solid #ffffff;
background-image: url('https://i.imgur.com/NT992d7.jpeg');
background-size: cover;
}
&__name {
text-align: center;
font-size: 2rem;
font-weight: bold;
color: #fff;
}
&__btm {
height: $cardBtmH;
background: #FFFFFF;
}
&__we {
text-align: center;
font-size: 2.2rem;
line-height: $cardBtmH;
}
&__choice {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
&:before {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 2rem;
height: 2rem;
margin-left: -1rem;
color: #fff;
border-radius: 50%;
box-shadow: -2rem -3rem #fff, 2rem -3rem #fff;
}
&:after {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 4rem;
height: 1.5rem;
margin-left: -2rem;
border: 0.6rem solid #fff;
border-bottom: none;
border-top-left-radius: 1.5rem;
border-top-right-radius: 1.5rem;
}
&.m--reject {
background: $orange;
}
&.m--like {
background: $green;
&:after {
transform: scaleY(-1);
}
}
}
&__drag {
z-index: 5;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
}
&__tip {
text-align: center;
font-size: 2.2rem;
}
}
.reject {
animation-duration: 1s;
animation-name: reject;
animation-fill-mode: forwards;
}
.reject-overlay {
animation-duration: .5s;
animation-name: reject-overlay;
animation-fill-mode: forwards;
}
.accept-overlay {
animation-duration: .5s;
animation-name: accept-overlay;
animation-fill-mode: forwards;
}
.accept {
animation-duration: 1s;
animation-name: accept;
animation-fill-mode: forwards;
}
@keyframes accept {
to {
transform: translateX(30rem) rotate(30deg);
}
}
@keyframes reject {
to {
transform: translateX(-30rem) rotate(-30deg);
}
}
@keyframes reject-overlay {
to {
opacity: 1;
}
}
@keyframes accept-overlay {
to {
opacity: 1;
}
}
body {
display: flex;
flex-direction: row;
overflow: hidden;
overflow-x: auto;
.slide {
width: 100vw;
}
.slide::after {
content: "\00a0";
}
}
.slide {
scroll-snap-stop: always;
}
:root {
animation: adjust-slide-index 3s steps(3, end), adjust-pos 1s;
animation-timeline: scroll(root x);
scroll-snap-type: x mandatory;
}
main {
display: flex;
align-items: center;
justify-content: space-between;
flex-flow: row nowrap;
font-family: monospace;
width: 100vw;
height: 100vh;
display: flex;
margin: 1em auto;
outline: 1px dashed lightgray;
flex-wrap: nowrap;
}
.slide {
text-align: center;
flex: none;
width: 100vw;
height: 100vh;
scroll-padding-left: 15vh;
}
#middle {
scroll-snap-align: center;
}
@for $i from 1 through 50 {
.scroll-trigger-#{$i} {
animation-timeline: --trigger-timeline-#{$i};
view-timeline-axis: x;
}
}
@property --scroll-position {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@property --scroll-position-delayed {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@property --scroll-direction {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@property --slide-index {
syntax: "<number>";
inherits: true;
initial-value: 0;
}
@keyframes adjust-pos {
to {
--scroll-position: 1;
--scroll-position-delayed: 1;
}
}
@keyframes adjust-slide-index {
to {
--slide-index: 3;
}
}
#debug {
counter-reset:
scroll-position calc(var(--scroll-position) * 100)
scroll-position-delayed calc(var(--scroll-position-delayed) * 100)
scroll-velocity calc(var(--scroll-velocity) * 100)
scroll-direction var(--scroll-direction)
scroll-speed calc(var(--scroll-speed) * 100)
slide-index var(--slide-index);
;
[data-id="--scroll-position"]::after {
content: "--scroll-position: " counter(scroll-position);
}
[data-id="--scroll-position-delayed"]::after {
content: "--scroll-position-delayed: " counter(scroll-position-delayed);
}
[data-id="--scroll-velocity"]::after {
content: "--scroll-velocity: " counter(scroll-velocity);
}
[data-id="--scroll-direction"]::after {
content: "--scroll-direction: " counter(scroll-direction);
}
[data-id="--scroll-speed"]::after {
content: "--scroll-speed: " counter(scroll-speed);
}
[data-id="--slide-index"]::after {
content: "--slide-index: " counter(slide-index);
}
}
.scroll-trigger-1, .scroll-trigger-2 {
display: none;
}
@container style(--scroll-direction: -1) and style(--slide-index: 0) {
.scroll-trigger-1 {
display: block;
}
}
@container style(--scroll-direction: 1) and style(--slide-index:2) {
.scroll-trigger-2 {
display: block;
}
}
@container style(--scroll-trigger-1: 1) {
.result {
background-image: url('https://counter6.optistats.ovh/private/freecounterstat.php?c=abtwsn99snah6wq42nhnsmbp6pxbrwtj');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.counter-description::after {
content: 'who like spider pig';
}
.scroll-trigger-2 {
display: none;
}
}
@container style(--scroll-trigger-2: 1) {
.result {
background-image: url('https://counter6.optistats.ovh/private/freecounterstat.php?c=qbgw71kxx1stgsf5shmwrb2aflk5wecz');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.counter-description::after {
content: 'who dislike spider pig';
}
.scroll-trigger-1{
display: none;
}
}
View Compiled