1

我开始为自己制作响应式作品集,但遇到了一些奇怪的故障,比如动画。

我的第一个问题是你能把关键帧放在媒体查询中吗?还是我需要制作两个动画并使用媒体查询从一个切换到另一个?

如果您转到投资组合 => 将窗口最小化为移动视图 => 我的云/鸟/波浪动画的大小将保持为桌面大小,除非您刷新页面,否则不会更改。

@media only screen and (max-width: 680px) {
    /* Clouds CSS3 animations */

    @-webkit-keyframes Clouds-Size {
        from {
            width: 25%;
        }
        50% {
            width: 30%;
        }
        to {
            width: 25%;
        }
    }
    @-moz-keyframes Clouds-Size {
        from {
            width: 25%;
        }
        50% {
            width: 30%;
        }
        to {
            width: 25%;
        }
    }
    @-ms-keyframes Clouds-Size {
        from {
            width: 25%;
        }
        50% {
            width: 30%;
        }
        to {
            width: 25%;
        }
    }

    /* End Clouds CSS3 Animation */

    /* Big Wave CSS3 animations */

    @-webkit-keyframes Wave-Big-Size {
        from {
            height: 10em;
        }
        50% {
            height: 9em;
        }
        to { 
            height: 10em;
        }
    }
    @-moz-keyframes Wave-Big-Size {
        from {
            height: 10em;
        }
        50% {
            height: 9em;
        }
        to { 
            height: 10em;
        }
    }
    @-ms-keyframes Wave-Big-Size {
        from {
            height: 10em;
        }
        50% {
            height: 9em;
        }
        to { 
            height: 10em;
        }
    }

    /* End Big Wave CSS3 Animation */
}

我的第二个(主要)问题是一个无限的 CSS3 关键帧动画似乎在几秒钟后出现故障,就像它对动画进行了硬刷新一样。

在我的投资组合中,我有两波从左到右,另一波从右到左。

底部的Big-Wave效果就像一个魅力,动画非常流畅,但较小的顶部波浪似乎在几秒钟后出现了小故障。这对我来说不是生死攸关的事,但对我来说很奇怪而且有点烦人。

这是本节的css:

.bigWave {
    background: url(../images/bigWave.svg) repeat-x;
    height: 7em;
    width: 100%;
    position: absolute;
    bottom: 0;
    -webkit-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
    -moz-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
    -ms-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
    -o-animation: Wave-Big 500s linear infinite, Wave-Big-Size 5s ease-in-out infinite;
}

@media only screen and (max-width: 680px) {
  .bigWave {
    height: 10em;
  }
}

.smallWave {
    background: url(../images/smallWave.svg) repeat-x;
    height: 6em;
    width: 100%;
    position: absolute;
    bottom: 4em;
    -webkit-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
    -moz-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
    -ms-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
    -o-animation: Wave-Small 500s linear infinite, Wave-Small-Size 5s ease-in-out infinite;
}

@media only screen and (max-width: 680px) {
  .smallWave {
    height: 12em;
  }
}

这是波浪动画的关键帧:

/* Big Wave CSS3 animations */

@-webkit-keyframes Wave-Big {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: 1300% 0%
    }
}
@-webkit-keyframes Wave-Big-Size {
    from {
        height: 7em;
    }
    50% {
        height: 6em;
    }
    to { 
        height: 7em;
    }
}
@-moz-keyframes Wave-Big {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: 1300% 0%
    }
}
@-moz-keyframes Wave-Big-Size {
    from {
        height: 7em;
    }
    50% {
        height: 6em;
    }
    to { 
        height: 7em;
    }
}
@-ms-keyframes Wave-Big {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: 1300% 0%
    }
}
@-ms-keyframes Wave-Big-Size {
    from {
        height: 7em;
    }
    50% {
        height: 6em;
    }
    to { 
        height: 7em;
    }
}

/* End Big Wave CSS3 Animation */

/* Small Wave CSS3 animations */

@-webkit-keyframes Wave-Small {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: -1300% 0%
    }
}
@-webkit-keyframes Wave-Small-Size {
    from {
        bottom: 4em;
    }
    50% {
        bottom: 3em;
    }
    to { 
        bottom: 4em;
    }
}
@-moz-keyframes Wave-Small {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: -1300% 0%
    }
}
@-moz-keyframes Wave-Small-Size {
    from {
        bottom: 4em;
    }
    50% {
        bottom: 3em;
    }
    to { 
        bottom: 4em;
    }
}
@-ms-keyframes Wave-Small {
    from {
        background-position: 5% 5%
    }
    to { 
        background-position: -1300% 0%
    }
}
@-ms-keyframes Wave-Small-Size {
    from {
        bottom: 4em;
    }
    50% {
        bottom: 3em;
    }
    to { 
        bottom: 4em;
    }
}

/* End Small Wave CSS3 Animation */

您认为可能是罪魁祸首的任何想法或建议?

非常感谢任何和所有帮助!这也是我第一次使用关键帧,所以欢迎提示!:]

文件夹

JSFIDDLE

4

2 回答 2

3

transform: translate();是硬件加速的,并且在制作动画时应该更平滑。例如,使用translateY代替的小波bottom不那么波涛汹涌:http: //jsfiddle.net/fE9t9/

/* Small Wave CSS3 animations */

@-webkit-keyframes Wave-Small {
    from { background-position: 5% 5% }
    to { background-position: -1300% 0% }
}
@-webkit-keyframes Wave-Small-Size {
    from, to { -webkit-transform: translateY(0); }
    50% { -webkit-transform: translateY(1em); }
}
@-moz-keyframes Wave-Small {
    from { background-position: 5% 5% }
    to { background-position: -1300% 0% }
}
@-moz-keyframes Wave-Small-Size {
    from, to { -moz-transform: translateY(0); }
    50% { -moz-transform: translateY(1em); }
}
@-o-keyframes Wave-Small {
    from { background-position: 5% 5% }
    to { background-position: -1300% 0% }
}
@-o-keyframes Wave-Small-Size {
    from, to { -o-transform: translateY(0); }
    50% { -o-transform: translateY(1em); }
}
@keyframes Wave-Small {
    from { background-position: 5% 5% }
    to { background-position: -1300% 0% }
}
@keyframes Wave-Small-Size {
    from, to { transform: translateY(0); }
    50% { transform: translateY(1em) }
}


/* Big Wave CSS3 animations */

@-webkit-keyframes Wave-Big {
    from { background-position: 5% 5% }
    to { background-position: 1300% 0% }
}
@-webkit-keyframes Wave-Big-Size {
    from, to { -webkit-transform: translateY(0); }
    50% { -webkit-transform: translateY(1em); }
}
@-moz-keyframes Wave-Big {
    from { background-position: 5% 5% }
    to { background-position: 1300% 0% }
}
@-moz-keyframes Wave-Big-Size {
    from, to { -moz-transform: translateY(0); }
    50% { -moz-transform: translateY(1em); }
}
@-o-keyframes Wave-Big {
    from { background-position: 5% 5% }
    to { background-position: 1300% 0% }
}
@-o-keyframes Wave-Big-Size {
    from, to { -o-transform: translateY(0); }
    50% { -o-transform: translateY(1em); }
}
@keyframes Wave-Big {
    from { background-position: 5% 5% }
    to { background-position: 1300% 0% }
}
@keyframes Wave-Big-Size {
    from, to { transform: translateY(0); }
    50% { transform: translateY(1em); }
}

注意:动画只支持IE10+;没有版本支持 -ms- 前缀,因此应将其删除。

translate动画稍微快一点;如果仅应用于 1 个波浪,则会出现轻微的不协调。所以translateY应该应用于两个波以使它们同步。根据您的喜好,可能需要对波浪的时间/运动进行一些新的调整。

于 2013-11-04T22:22:22.810 回答
1

至于第一个问题,您可以将它们放在您想要的位置,但它不会像您希望的那样工作。它确实改变了动画本身,但新装修的动画并没有应用于元素。你需要用一点js来切换到新的

(应该)解决第二个问题的一种方法是使动画持续x时间更长,并使背景位置x时间也更大。这里的例子

不过,我建议您清理代码格式,这样可以更轻松地跟踪它,并且可能会显示您没有考虑的隐藏问题

于 2013-11-04T20:05:42.117 回答