3D Card Flip with Touch & Mouse Drag – TouchFlip3D-Web
It requires no external dependencies and uses the Shadow DOM to keep its internal styles completely isolated from the host page.
front and back). You control the markup and styling of each face completely.{passive: false} only where cancellation is required, so scroll performance on the rest of the page is preserved.1. Install touch-flip-3d-web and import it into your main JS file:
# NPM $ npm install touch-flip-3d-web
import 'touch-flip-3d-web';
2. Or directly import the ‘TouchFlip3D.js’ file into your HTML document.
<script src="TouchFlip3D.js"></script>
3. After the script loads, the <touch-flip-3d> custom element is globally available. Place your front and back content inside it using the named slot attributes:
<!--
Set explicit width and height on the component.
The inner faces will stretch to fill this container.
-->
<touch-flip-3d style="width: 320px; height: 200px;">
<!-- The front face — shown by default -->
<div slot="front" style="background: #0f3460; color: #eaeaea; border-radius: 12px; padding: 24px;">
<h3>Developer Profile</h3>
<p>Drag or swipe to flip</p>
</div>
<!-- The back face — rotated 180deg on the Y axis initially -->
<div slot="back" style="background: #16213e; color: #eaeaea; border-radius: 12px; padding: 24px;">
<h3>Contact Info</h3>
<p>hello@example.dev</p>
</div>
</touch-flip-3d> 4. You can place multiple <touch-flip-3d> elements on the same page. Each instance manages its own drag state internally.
<div style="display: flex; gap: 24px; flex-wrap: wrap;">
<!-- Card 1: Pricing tier -->
<touch-flip-3d style="width: 280px; height: 180px;">
<div slot="front" style="background: #1b4332; color: white; border-radius: 10px; padding: 20px;">
<h4>Starter Plan</h4>
<p>$9 / month</p>
</div>
<div slot="back" style="background: #2d6a4f; color: white; border-radius: 10px; padding: 20px;">
<ul>
<li>10 projects</li>
<li>5 GB storage</li>
<li>Email support</li>
</ul>
</div>
</touch-flip-3d>
<!-- Card 2: Another tier -->
<touch-flip-3d style="width: 280px; height: 180px;">
<div slot="front" style="background: #7b2d8b; color: white; border-radius: 10px; padding: 20px;">
<h4>Pro Plan</h4>
<p>$29 / month</p>
</div>
<div slot="back" style="background: #5e2270; color: white; border-radius: 10px; padding: 20px;">
<ul>
<li>Unlimited projects</li>
<li>50 GB storage</li>
<li>Priority support</li>
</ul>
</div>
</touch-flip-3d>
</div> 5. The component uses perspective: 1200px on the host element. To get a deeper or shallower 3D effect, wrap the <touch-flip-3d> in a container and apply your own perspective to that wrapper:
/* Adjust the depth of the 3D perspective from outside the component */.card-wrapper {
perspective: 800px; /* lower value = more dramatic depth */} Each slotted face fills 100% of the component’s width and height. Set the dimensions on the <touch-flip-3d> element, not on the child divs:
touch-flip-3d {
width: 360px;
height: 220px;
display: block; /* the component sets this in Shadow DOM, but explicit is safe */} The post 3D Card Flip with Touch & Mouse Drag – TouchFlip3D-Web appeared first on CSS Script.
Fresh from its huge early access launch, underwater survival and crafting adventure game Subnautica 2…
dither-avatar is a lightweight, zero-dependency JavaScript library that generates deterministic, dithered SVG avatars from any…
The cyber battlefield in Eastern Europe is escalating once again. Relentless Russian state-sponsored threat actors…
Three critical vulnerabilities have been disclosed in n8n, the popular open-source workflow automation platform, any…
A critical pre-authentication remote code execution (RCE) vulnerability has been discovered in Marimo, a widely…
A critical heap buffer overflow flaw in F5 NGINX, tracked as CVE-2026-42945, has moved from disclosure…
This website uses cookies.