使用animation.css库快速实现CSS3旋转动画效果

06-01 1129阅读

CSS3旋转动画效果实现(使用Animate.css)

下面我将展示如何使用Animate.css库快速实现各种CSS3旋转动画效果,同时提供一个直观的演示界面。

思路分析

  1. 引入Animate.css库
  2. 创建不同旋转动画的展示区域
  3. 添加控制面板自定义动画效果
  4. 实现实时预览功能

最终实现代码



    
    
    Animate.css旋转动画效果
    
    
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            color: #fff;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        header {
            text-align: center;
            padding: 40px 0;
            margin-bottom: 30px;
        }
        
        h1 {
            font-size: 3.5rem;
            text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            margin-bottom: 10px;
            background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fad0c4, #a18cd1);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
        }
        
        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 30px;
            margin-bottom: 50px;
        }
        
        .card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            transition: transform 0.3s ease;
        }
        
        .card:hover {
            transform: translateY(-5px);
        }
        
        .card h2 {
            font-size: 1.8rem;
            margin-bottom: 20px;
            color: #ffcc00;
            text-align: center;
        }
        
        .preview-area {
            height: 200px;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 20px 0;
        }
        
        .animated-element {
            width: 100px;
            height: 100px;
            background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fad0c4, #a18cd1);
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 3rem;
            color: white;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        
        .controls {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            margin-bottom: 40px;
        }
        
        .controls h2 {
            font-size: 2rem;
            margin-bottom: 25px;
            color: #ffcc00;
            text-align: center;
        }
        
        .control-group {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .control-item {
            flex: 1;
            min-width: 250px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        select, input {
            width: 100%;
            padding: 12px;
            border-radius: 8px;
            border: none;
            background: rgba(255, 255, 255, 0.15);
            color: white;
            font-size: 1rem;
        }
        
        button {
            background: linear-gradient(45deg, #ff9a9e, #a18cd1);
            color: white;
            border: none;
            padding: 15px 30px;
            font-size: 1.1rem;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: block;
            margin: 30px auto 0;
            font-weight: bold;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        
        button:hover {
            transform: scale(1.05);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
        }
        
        .code-container {
            background: rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            padding: 20px;
            font-family: monospace;
            font-size: 1.1rem;
            overflow-x: auto;
            margin-top: 20px;
        }
        
        .code-highlight {
            color: #ffcc00;
        }
        
        footer {
            text-align: center;
            padding: 30px 0;
            font-size: 1rem;
            opacity: 0.8;
        }
        
        .info {
            margin-top: 20px;
            padding: 15px;
            background: rgba(255, 204, 0, 0.15);
            border-radius: 8px;
            border-left: 4px solid #ffcc00;
        }
        
        @media (max-width: 768px) {
            h1 {
                font-size: 2.5rem;
            }
            
            .grid {
                grid-template-columns: 1fr;
            }
        }
    


    

Animate.css 旋转动画效果

Animate.css 是一个现成的跨浏览器动画库,可用于您的 Web 项目。通过这个演示页面,您可以快速预览各种旋转动画效果并轻松集成到您的项目中。

自定义动画效果

选择动画效果: 旋转进入 (rotateIn) 左下旋转进入 (rotateInDownLeft) 右下旋转进入 (rotateInDownRight) 左上旋转进入 (rotateInUpLeft) 右上旋转进入 (rotateInUpRight) 旋转退出 (rotateOut) 左下旋转退出 (rotateOutDownLeft) 右下旋转退出 (rotateOutDownRight) 左上旋转退出 (rotateOutUpLeft) 右上旋转退出 (rotateOutUpRight)
动画时长 (秒): 1.0 秒
动画延迟 (秒): 0.0 秒
应用动画效果

HTML代码:

<div token tag">animate__rotateIn"">>元素内容</div">>

CSS代码:

.animate__animated {
  --animate-duration: 1s;
  --animate-delay: 0s;
}

旋转进入

类名: animate__rotateIn

元素从透明状态旋转出现,适合元素进入场景时的动画效果。

左下旋转进入

↙️

类名: animate__rotateInDownLeft

元素从屏幕左下方旋转进入,创造从角落进入的视觉效果。

旋转退出

类名: animate__rotateOut

元素旋转并逐渐消失,适合元素离开场景时的动画效果。

右上旋转退出

↗️

类名: animate__rotateOutUpRight

元素向右上方旋转并消失,创造飞向屏幕右上角的效果。

© 2023 CSS3旋转动画效果演示 | 使用Animate.css v4.1.1

使用animation.css库快速实现CSS3旋转动画效果
(图片来源网络,侵删)

提示:在实际项目中,您只需添加相应的类名即可应用这些动画效果

document.addEventListener('DOMContentLoaded', function() { // 获取DOM元素 const animationType = document.getElementById('animationType'); const animationDuration = document.getElementById('animationDuration'); const animationDelay = document.getElementById('animationDelay'); const durationValue = document.getElementById('durationValue'); const delayValue = document.getElementById('delayValue'); const applyButton = document.getElementById('applyButton'); const customElement = document.getElementById('customElement'); const codeClass = document.getElementById('codeClass'); const codeDuration = document.getElementById('codeDuration'); const codeDelay = document.getElementById('codeDelay'); // 更新时长显示 animationDuration.addEventListener('input', function() { durationValue.textContent = this.value + ' 秒'; codeDuration.textContent = this.value + 's'; }); // 更新延迟显示 animationDelay.addEventListener('input', function() { delayValue.textContent = this.value + ' 秒'; codeDelay.textContent = this.value + 's'; }); // 应用动画按钮 document.getElementById('applyAnimation').addEventListener('click', function() { // 移除之前的动画类 customElement.className = 'animated-element'; // 添加新的动画类 const selectedAnimation = 'animate__' + animationType.value; codeClass.textContent = selectedAnimation; // 添加动画类 customElement.classList.add('animate__animated', selectedAnimation); // 设置自定义属性 customElement.style.setProperty('--animate-duration', animationDuration.value + 's'); customElement.style.setProperty('--animate-delay', animationDelay.value + 's'); // 重新触发动画 void customElement.offsetWidth; }); // 为每个卡片添加点击预览功能 document.querySelectorAll('.card .animated-element').forEach(element => { element.addEventListener('click', function() { // 获取动画类名 const classes = this.className.split(' '); const animationClass = classes.find(cls => cls.startsWith('animate__') && cls !== 'animate__animated'); if (animationClass) { // 在控制面板中设置对应的值 animationType.value = animationClass.replace('animate__', ''); codeClass.textContent = animationClass; // 应用动画到自定义元素 customElement.className = 'animated-element'; customElement.classList.add('animate__animated', animationClass); // 显示消息 alert(`已应用动画: ${animationClass}`); } }); }); });

功能说明

这个页面展示了如何使用Animate.css实现各种CSS3旋转动画效果:

使用animation.css库快速实现CSS3旋转动画效果
(图片来源网络,侵删)
  1. 预设动画展示区:

    • 展示了4种不同的旋转动画效果(rotateIn, rotateInDownLeft, rotateOut, rotateOutUpRight)
    • 每个卡片包含动画预览和说明信息
    • 自定义控制面板:

      使用animation.css库快速实现CSS3旋转动画效果
      (图片来源网络,侵删)
      • 可选择10种不同的旋转动画效果
      • 可调整动画时长(0.5秒至5秒)
      • 可设置动画延迟时间(0秒至3秒)
      • 实时预览自定义动画效果
      • 代码生成:

        • 显示应用动画所需的HTML和CSS代码
        • 代码会根据用户选择实时更新
        • 交互功能:

          • 点击预设卡片可直接在自定义区域预览效果
          • 应用按钮可应用自定义设置

使用说明

  1. 在自定义控制面板中选择动画效果
  2. 调整动画时长和延迟时间
  3. 点击"应用动画效果"按钮查看结果
  4. 复制生成的代码到您的项目中

这个页面完全响应式,可在各种设备上正常显示,并使用了现代化的UI设计,包括毛玻璃效果、渐变背景和卡片式布局。

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们。

目录[+]

取消
微信二维码
微信二维码
支付宝二维码