For Tailwind CSS v3 docs, click here.

3D效果卡片

一个3D透视效果卡片,将鼠标悬停在卡片上以提升卡片元素。

通过 CLI 安装

npm
pnpm
bun
yarn
npx shadcn-vue@latest add "https://registry.inspira-ui.com/card-3d.json"

手动安装

在同一个文件中,复制并粘贴以下代码:

CardContainer.vue
CardBody.vue
CardItem.vue
useMouseState.ts

示例

With rotation

API

CardContainer

The CardContainer component serves as a wrapper for the 3D card effect. It manages mouse events to create a 3D perspective.

Props

Prop 名称类型默认值描述
classStringnullAdditional classes for styling the inner container element.
containerClassStringnullAdditional classes for styling the outer container element.

用例

MyCardComponent.vue
<CardContainer containerClass="additional-class">
  <!-- Your content here -->
</CardContainer>

CardBody

The CardBody component is a flexible container with preserved 3D styling. It is intended to be used within a CardContainer to hold content with a 3D transformation effect.

Props

Prop 名称类型默认值描述
classStringnullAdditional classes for custom styling.

用例

MyCardComponent.vue
<CardBody class="custom-class">
  <!-- Your content here -->
</CardBody>

CardItem

The CardItem component represents individual items within the 3D card. It supports various transformations (translation and rotation) to create dynamic 3D effects.

Props

Prop 名称类型默认值描述
asString"div"The HTML tag or component to use for the item.
classStringnullAdditional classes for styling the item.
translateXNumber/String0X-axis translation in pixels.
translateYNumber/String0Y-axis translation in pixels.
translateZNumber/String0Z-axis translation in pixels, used to control the depth effect.
rotateXNumber/String0X-axis rotation in degrees.
rotateYNumber/String0Y-axis rotation in degrees.
rotateZNumber/String0Z-axis rotation in degrees.

用例

MyCardComponent.vue
<CardItem as="p" translateZ="50" class="custom-item-class">
  Your text or content here
</CardItem>