zoukankan      html  css  js  c++  java
  • 项目实战中遇到的关于transition 和 animation 的犯错体会

    响应式简历里面的头像边框要求鼠标悬停在头像区域时,box-shadow放大后再缩小的闪烁效果

    一开始用的transition,效果接近,但没有闪烁效果

    .user-inform .user-img {
        margin-top: 80px;
        margin-left: auto;
        margin-right: auto;
         120px;
        height: 120px;
        background-color: white;
        border-radius: 50%;
        box-shadow: 0 0 0 5px #88bde8;
        transition: box-shadow 1s ease 0s; 

      .user-inform .user-img:hover {
          box-shadow: 0 0 5px 10px #88bde8;
     

    一开始甚至把transition的一些属性和animation的搞混了,写成了 transition: box-shadow 1s ease infinite; 在chrome的调试工具窗中发现了报错

    注意:transition的属性是 transition-property(属性), transition-duration(持续时间), transition-timing-function(动效/缓动函数), transition-delay(延迟时间)

    所以transition 并没有 infinite 这个属性

    改用animation后,闪烁效果成功做出,但是变成一直在闪烁,而不是最初想要的只有鼠标悬停时才变化

    .user-inform .user-img {
        margin-top: 80px;
        margin-left: auto;
        margin-right: auto;
        width: 120px;
        height: 120px;
        background-color: white;
        border-radius: 50%;
        box-shadow: 0 0 0 5px #88bde8;
        animation: circleRun 1s ease infinite;
    }
    
    @keyframes circleRun {
        0% {
            box-shadow: 0 0 0 5px #88bde8;
        }
        50% {
            box-shadow: 0 0 5px 10px #88bde8;
        }
        100% {
            box-shadow: 0 0 0 5px #88bde8;
        }
    }

    再修改一下,成功了

    .user-inform .user-img {
        margin-top: 80px;
        margin-left: auto;
        margin-right: auto;
        width: 120px;
        height: 120px;
        background-color: white;
        border-radius: 50%;
        box-shadow: 0 0 0 5px #88bde8;
    }
    
    .user-inform .user-img:hover {
        animation: circleRun 1s ease infinite;
    }
    
    @keyframes circleRun {
        0% {
            box-shadow: 0 0 0 5px #88bde8;
        }
        50% {
            box-shadow: 0 0 5px 10px #88bde8;
        }
        100% {
            box-shadow: 0 0 0 5px #88bde8;
        }
    }
  • 相关阅读:
    超实用的PHP代码片段
    推荐五款优秀的PHP代码重构工具
    PHP开发搜索引擎技术全解析
    怎样成为一名PHP专家?
    PHP中该怎样防止SQL注入?
    有关PHP 10条有用的建议
    fir.im Weekly
    可能是一场很 IN 的技术分享
    fir.im Weekly
    更新日志
  • 原文地址:https://www.cnblogs.com/chivasknight/p/8203641.html
Copyright © 2011-2022 走看看