-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started adding 3d effect to cardhover
- Loading branch information
Showing
6 changed files
with
187 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script> | ||
const $card = document.querySelector('.card'); | ||
let bounds; | ||
function rotateToMouse(e) { | ||
const mouseX = e.clientX; | ||
const mouseY = e.clientY; | ||
const leftX = mouseX - bounds.x; | ||
const topY = mouseY - bounds.y; | ||
const center = { | ||
x: leftX - bounds.width / 2, | ||
y: topY - bounds.height / 2 | ||
} | ||
const distance = Math.sqrt(center.x**2 + center.y**2); | ||
$card.style.transform = ` | ||
scale3d(1.07, 1.07, 1.07) | ||
rotate3d( | ||
${center.y / 100}, | ||
${-center.x / 100}, | ||
0, | ||
${Math.log(distance)* 2}deg | ||
) | ||
`; | ||
$card.querySelector('.glow').style.backgroundImage = ` | ||
radial-gradient( | ||
circle at | ||
${center.x * 2 + bounds.width/2}px | ||
${center.y * 2 + bounds.height/2}px, | ||
#ffffff55, | ||
#0000000f | ||
) | ||
`; | ||
} | ||
$card.addEventListener('mouseenter', () => { | ||
bounds = $card.getBoundingClientRect(); | ||
document.addEventListener('mousemove', rotateToMouse); | ||
}); | ||
$card.addEventListener('mouseleave', () => { | ||
document.removeEventListener('mousemove', rotateToMouse); | ||
$card.style.transform = ''; | ||
$card.style.background = ''; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% set custom_id = "test12345"%} | ||
<section data-transition="zoom" data-background-image="images/theme.jpg" data-background-opacity="0.2" | ||
id="{{custom_id}}" scry="7d1e12de-de62-4e13-ad1a-43ef80ff4322"> | ||
|
||
<h3 >Artwork</h3> | ||
<div class="r-stack mb-5"> | ||
<small class="fragment fade-out " data-fragment-index="1">???</small> | ||
<a target="_blank" href="#"> | ||
<small | ||
class="fragment fade-up title text-white hover:text-blue-200 " | ||
data-fragment-index="1"></small> | ||
</a> | ||
</div> | ||
|
||
<hr class="mx-5"> | ||
<div class="w-2/3 m-10 box aspect-[88/63] grid place-items-center relative r-stack rounded-3xl mx-auto drop-shadow | ||
hover:drop-shadow-xl card bg-[url({{'../images/art/art1.png' | url }})] bg-cover overflow-clip"> | ||
<div class="glow w-full aspect-[88/63] "></div> | ||
|
||
</div> | ||
|
||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters