Appearance
ThreedCard
<script setup lang="ts"></script>
<template>
<div class="threed-card">
<div class="card">
<div class="wrapper">
<img
src="https://ggayane.github.io/css-experiments/cards/dark_rider-cover.jpg"
class="cover-image"
/>
</div>
<img
src="https://ggayane.github.io/css-experiments/cards/dark_rider-title.png"
class="title"
/>
<img
src="https://ggayane.github.io/css-experiments/cards/dark_rider-character.webp"
class="character"
/>
</div>
<!--
<a
href="https://www.mythrillfiction.com/force-mage"
alt="Mythrill"
target="_blank"
>
<div class="card">
<div class="wrapper">
<img
src="https://ggayane.github.io/css-experiments/cards/force_mage-cover.jpg"
class="cover-image"
/>
</div>
<img
src="https://ggayane.github.io/css-experiments/cards/force_mage-title.png"
class="title"
/>
<img
src="https://ggayane.github.io/css-experiments/cards/force_mage-character.webp"
class="character"
/>
</div>
</a> -->
</div>
</template>
<style scoped lang="scss">
.threed-card {
--card-height: 600px;
--card-width: calc(var(--card-height) / 1.5);
.card {
width: var(--card-width);
height: var(--card-height);
position: relative;
display: flex;
justify-content: center;
align-items: flex-end;
padding: 0 36px;
perspective: 2500px;
margin: 0 50px;
}
.cover-image {
width: 100%;
height: 100%;
object-fit: cover;
}
.wrapper {
transition: all 0.5s;
position: absolute;
width: 100%;
z-index: -1;
}
.card:hover .wrapper {
transform: perspective(900px) translateY(-5%) rotateX(25deg) translateZ(0);
box-shadow: 2px 35px 32px -8px rgba(0, 0, 0, 0.75);
-webkit-box-shadow: 2px 35px 32px -8px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 2px 35px 32px -8px rgba(0, 0, 0, 0.75);
}
.wrapper::before,
.wrapper::after {
content: '';
opacity: 0;
width: 100%;
height: 80px;
transition: all 0.5s;
position: absolute;
left: 0;
}
.wrapper::before {
top: 0;
height: 100%;
background-image: linear-gradient(
to top,
transparent 46%,
rgba(12, 13, 19, 0.5) 68%,
rgba(12, 13, 19) 97%
);
}
.wrapper::after {
bottom: 0;
opacity: 1;
background-image: linear-gradient(
to bottom,
transparent 46%,
rgba(12, 13, 19, 0.5) 68%,
rgba(12, 13, 19) 97%
);
}
.card:hover .wrapper::before,
.wrapper::after {
opacity: 1;
}
.card:hover .wrapper::after {
height: 120px;
}
.title {
width: 100%;
transition: transform 0.5s;
}
.card:hover .title {
transform: translate3d(0%, -50px, 100px);
}
.character {
width: 100%;
opacity: 0;
transition: all 0.5s;
position: absolute;
z-index: -1;
}
.card:hover .character {
opacity: 1;
transform: translate3d(0%, -30%, 100px);
}
}
</style>
steam-card
<script setup lang="ts">
import { onMounted, ref } from 'vue';
const card = ref()
onMounted(() => {
card.value.addEventListener('mousemove', (e) => {
const cardHeight = card.value.offsetHeight;
const cardWidth = card.value.offsetWidth;
const { offsetX, offsetY } = e;
const hightlightValue = 1.5 - 1 * (offsetY / cardHeight);
card.value.style.setProperty('--brightness', hightlightValue)
let rotateYValue = Math.floor(-20 + 40 * (offsetX / cardWidth));
let rotateXValue = Math.floor(20 - 40 * (offsetY / cardHeight));
card.value.style.setProperty('--rotateX', `${rotateXValue}deg`)
card.value.style.setProperty('--rotateY', `${rotateYValue}deg`)
})
card.value.addEventListener('mouseleave', (e) => {
card.value.style.setProperty('--brightness', 1)
card.value.style.setProperty('--rotateX', 0)
card.value.style.setProperty('--rotateY', 0)
})
})
</script>
<template>
<div class="card-container">
<img class="card" src="./steam-card.png" ref="card" />
</div>
</template>
<style scoped lang="scss">
.card-container {
perspective: 200px;
// width: fit-content;
display: flex;
height: 300px;
justify-content: center;
align-items: center;
.card {
width: 200px;
height: 233px;
--brightness: 1;
--rotateX: 0deg;
--rotateY: 0deg;
filter: brightness(var(--brightness));
transform: rotateX(var(--rotateX, 0)) rotateY(var(--rotateY, 0));
border-radius: 5% / 3.5%;
transition: transform 0.1s ease,
box-shadow 0.2s ease,
scale 0.2s ease;
scale: 1;
&:hover {
box-shadow: 0 20px 40px black;
scale: 1.5;
cursor: pointer;
}
}
}
</style>
open-book
Hello
Hover Me
<template>
<div class="book">
<p>Hello</p>
<div class="cover">
<p>Hover Me</p>
</div>
</div>
</template>
<script setup lang='ts'>
</script>
<style scoped>
.book {
position: relative;
border-radius: 10px;
width: 220px;
height: 300px;
background-color: whitesmoke;
-webkit-box-shadow: 1px 1px 12px #000;
box-shadow: 1px 1px 12px #000;
-webkit-transform: preserve-3d;
-ms-transform: preserve-3d;
transform: preserve-3d;
-webkit-perspective: 2000px;
perspective: 2000px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
color: #000;
}
.cover {
top: 0;
position: absolute;
background-color: lightgray;
width: 100%;
height: 100%;
border-radius: 10px;
cursor: pointer;
-webkit-transition: all 0.5s;
transition: all 0.5s;
-webkit-transform-origin: 0;
-ms-transform-origin: 0;
transform-origin: 0;
-webkit-box-shadow: 1px 1px 12px #000;
box-shadow: 1px 1px 12px #000;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.book:hover .cover {
-webkit-transition: all 0.5s;
transition: all 0.5s;
-webkit-transform: rotatey(-80deg);
-ms-transform: rotatey(-80deg);
transform: rotatey(-80deg);
}
p {
font-size: 20px;
font-weight: bolder;
}
</style>