3D animated TIlt card design

 3D animated TIlt card design



It seems like you're building a blog post and providing various code snippets and tutorial content. Below is the refined and improved version of your HTML example, along with comments added to the code for clarity. This code is specifically for creating 3D animated tilt cards using Tilt.js and CSS.

3D Tilt Card Design Example (HTML, CSS, and JS)


index.html


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tilt Animation Cards Design</title>
  <!-- Link to the external CSS file for styling -->
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- Container holding the tilt animation cards -->
  <div class="container">
    <!-- Each card will have a 3D tilt effect when hovered -->
    <div class="card" data-tilt>
      <!-- Example image for the card -->
      <img src="https://i0.wp.com/i.pinimg.com/originals/ca/ba/45/caba456db19dca113ca53e115e21570c.jpg?resize=160,120" alt="Image 1">  
    </div>

    <div class="card" data-tilt>
      <!-- Another image for a different card -->
      <img src="https://fuselabcreative.com/wp-content/uploads/2023/07/mobile-apps-design-trends.jpg" alt="Image 2">
    </div>

    <div class="card" data-tilt>
      <!-- Same image as the first card, just repeated for demonstration -->
      <img src="https://i0.wp.com/i.pinimg.com/originals/ca/ba/45/caba456db19dca113ca53e115e21570c.jpg?resize=160,120" alt="Image 3">  
    </div>

    <div class="card" data-tilt>
      <!-- Another image to create variety -->
      <img src="https://fuselabcreative.com/wp-content/uploads/2023/07/mobile-apps-design-trends.jpg" alt="Image 4">
    </div>
  </div>

  <!-- Include jQuery for better browser compatibility -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

  <!-- Include Tilt.js for the tilt effect -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tilt.js/1.2.1/tilt.jquery.min.js"></script>
 
  <!-- Custom script to activate tilt effect on elements with the 'data-tilt' attribute -->
  <script>
    // Activate tilt effect on all elements with the 'data-tilt' attribute
    $(document).ready(function() {
      $('.card').tilt({
        scale: 1.1, // Set the tilt scale effect (higher value = more tilt)
        maxTilt: 25, // Maximum tilt angle in degrees
        speed: 400, // Speed of the tilt effect
        easing: "cubic-bezier(.03,.98,.52,.99)" // Smooth easing for the effect
      });
    });
  </script>
</body>
</html>


style.css
    /* Reset default margin and padding for all elements */
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    /* Make sure the body takes up the full height of the screen */
    body,
    html {
        height: 100%;
        font-family: Arial, sans-serif;
    }

    /* Center the content of the page */
    .container {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100%;
        gap: 20px;
        /* Space between cards */
        flex-wrap: wrap;
    }

    /* Style for each individual card */
    .card {
        width: 250px;
        height: 200px;
        background-color: #f0f0f0;
        border-radius: 10px;
        overflow: hidden;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s ease-in-out;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* Style for images inside cards */
    .card img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 8px;
    }

    /* Optional: Add hover effect (e.g., scaling) for the card */
    .card:hover {
        transform: scale(1.05);
}
    
Explanation and Comments:
  1. HTML Structure:

    • The HTML contains a .container div that holds multiple .card divs. Each card is decorated with a data-tilt attribute, which is used by Tilt.js to activate the tilt animation when hovered over.
    • The <img> tags inside the cards load images, which are used to visually represent the card.
  2. CSS Styling:

    • * { box-sizing: border-box; }: Ensures that padding and borders are included in the element's total width and height.
    • The .container is styled to use flexbox to arrange the cards in a row with equal spacing.
    • Each .card is given a fixed width and height, with rounded corners and a shadow effect to create the appearance of a 3D card.
    • card:hover: This provides a small scaling effect when the user hovers over the card to give it a subtle interactive feel.
  3. Tilt.js Setup:

    • Tilt.js is a lightweight library used to create 3D tilt animations on elements. It is initialized with specific options such as scale, maxTilt, speed, and easing.
    • scale: 1.1: Increases the card size when hovered for a more pronounced tilt effect.
    • maxTilt: 25: The card can tilt up to 25 degrees.
    • speed: 400: The transition speed for the tilt effect.
    • easing: Specifies the easing function for the tilt animation.
  4. jQuery:

    • jQuery is used to ensure that the DOM is fully loaded before applying the tilt() function to the .card elements.

Conclusion:

This setup creates an interactive, 3D tilt effect on the cards using Tilt.js, which is powered by jQuery for better browser compatibility. You can easily add or remove cards and customize the images as needed. The effect adds a professional touch to any website, especially for portfolios or product showcases.

Feel free to adapt the code to your blog content by following the structure and adding your own content!


Comments

Popular posts from this blog

Lets build a Markdown blog using Next.js, Shadcn, Tailwind, Pieces, Remark & Rehype 🔥

React Portflio Website Basic to Advance

Todo List app using html,js and tailwind.css with features login,logout,storing the data in localstorage addtodos,deletetodos and updating todos,toastify library and many more