【问题标题】:How can you make an element animate back to original positioning upon screen size reduction?如何在屏幕尺寸缩小时让元素动画回到原始位置?
【发布时间】:2020-09-14 01:14:09
【问题描述】:

大家好^^ 我为我设计的 SVG 徽标创建了幻灯片动画。使用媒体查询在屏幕大小上使用关键帧动画将图像向左滑动并不困难。但是,我无法让 SVG 通过动画或过渡延迟等方式滑回中心(原始位置)。在更改回较小的媒体查询大小后,SVG 只是跳转到其原始位置(页面上的主徽标)。

我无法找到解决此问题的方法。但是,下面是代码笔的链接。如果您认为您可以提供帮助,我将由衷地感谢您。谢谢。

https://codepen.io/shaunbolak/pen/RwWmgVK

/* ============================================= */
/*          SVG Keyframes                        */
/* ============================================= */

@keyframes offset {
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes mobile-path-fill {
    100% {
        fill: $logo-main-path-color;
    }
}


@keyframes fill-desktop {
    100% {
        fill: $logo-alternate-path-color;
    }
}

@keyframes move-left {
    100% {
        transform: translateX(-118%);
    }
}

/* ============================================= */
/*          Main logo                            */
/* ============================================= */


#logo {
    padding-top: 15px;
    height: 150px;
    width: 350px; 

    @include for-size(desktop-up) {
        animation: move-left 2s forwards;
        padding-top: 20px;
        height: 120px;
        width: 300px;
        transition: width 1s;
    }

    @include for-size(larger-desktop-up) {
        width: 350px;
        transition: width 1s;
    }

    @include for-size(big-desktop-up) {
        width: 400px;
        transition: width 1s;
    }
}


#logoFill {
    fill: $logo-main-fill;
    stroke: $logo-main-fill;

    @include for-size(desktop-up) {
        animation: fill-desktop 1.5s 1.2s forwards;
    }
}

.logo-stroke {
    stroke: $logo-main-path-color;
    stroke-width: 1;
    stroke-dasharray: 325;
    stroke-dashoffset: 325;
    animation: offset 3s linear forwards, mobile-path-fill 1.2s 3s forwards;
}

【问题讨论】:

    标签: css svg sass


    【解决方案1】:

    添加:

    @keyframes move-right {
      from {
        transform: translateX(-118%);
      } to {
        transform: translateX(0);
      }
    }
    

    然后:

    @media (max-width: 1200px) {
      #logo {
        animation: move-right 2s;
        padding-top: 20px;
        height: 120px;
        width: 300px;
        transition: width 1s;
      }
    }
    

    我已经检查过了,它运行良好......

    【讨论】:

    • 您好 Joseph^^ 非常感谢您的回复和帮助。不幸的是,我没有看到任何区别:/
    • 我完全错了。我使用了一个代码比较工具,并且我有一个用于 svg 动画的冗余规则(重复规则) - 你的修复工作完美。谢谢你,好心的先生^^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多