zoukankan      html  css  js  c++  java
  • CSS Module解决全局或本地使用@keyframes无效问题

    最近使用CSSModule开发react项目,遇到一个问题,使用@keyframes无效,问题如下

    /** less + css module **/
    :global {
       .effect-bottom {
          animation: globeRotate 0.5s linear infinite;
        }
    
        @keyframes globeRotate {
          from {
            transform: rotate(0deg);
          }
    
          to {
            transform: rotate(-360deg);
          }
        }
    }
    
    /** 编译结果如下 **/
    .pages-style-gameWrap .effect-bottom {
      top: auto;
      bottom: 0;
      animation: globeRotate 0.5s linear infinite;
    }
    @keyframes pages-style-globeRotate {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(-360deg);
      }
    }

    可以看到 @keyframes 名称也被编译了,这样就获取不到 @keyframes 的名称了,解决办法如下(只需在调用@keyframes的元素后面添加 :local  就行了)

    :global {
        .effect-bottom :local {
          animation: globeRotate 0.5s linear infinite;
        }
    
        @keyframes globeRotate {
          from {
            transform: rotate(0deg);
          }
    
          to {
            transform: rotate(-360deg);
          }
        }
    }
    
    /** 编译结果如下 **/
    .pages-style-gameWrap .effect-bottom {
      top: auto;
      bottom: 0;
      animation: pages-style-globeRotate 0.5s linear infinite;
    }
    @keyframes pages-style-globeRotate {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(-360deg);
      }
    }
  • 相关阅读:
    后台服务器经典面试题
    Java英语面试题(核心知识篇)
    Java常用英语汇总(面试必备)
    字符压缩编码
    外排序
    基数排序
    Windows Server 2008 R2 部署服务
    LINUX中常用操作命令
    我的学习笔记_Windows_HOOK编程 2009-12-03 11:19
    CSDN-Code平台使用过程中的5点经验教训
  • 原文地址:https://www.cnblogs.com/victorlyw/p/12295673.html
Copyright © 2011-2022 走看看