【问题标题】:Is it possible to use CSS3 animations to move an image up and down while infinitely scrolling side to side?是否可以使用 CSS3 动画在无限滚动的同时上下移动图像?
【发布时间】:2013-10-28 09:20:29
【问题描述】:

我有一个问题,我希望只用 CSS3 动画就可以实现,但如果需要使用 jQuery 动画,那也没关系。 :]

我有一张云从右向左滑动的图像,上面有一个无限循环。这很好用,我很喜欢 CSS3 动画,但我找不到任何关于向它们添加垂直动画的信息。

如果这可以实现我的云图像稍微上下移动,随机是可能的,所以它们不只是直接滑过,那将是史诗般的。我是 CSS3 动画的新手,所以我在 keyframes 上读过一些东西,但是,我尝试过几次使用基于 % 的关键帧,我并没有成功地让它们工作。

这是我需要做的,还是最好只使用 jQuery 来达到我想要的效果。

CSS

.clouds {
    width: 20em;
    position: absolute;
    top: 1em;
    -webkit-animation-name: Clouds;
    -webkit-animation-duration: 50s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
    -moz-animation-name: Clouds;
    -moz-animation-duration: 50s;
    -moz-animation-timing-function: linear;
    -moz-animation-iteration-count: infinite;
    -ms-animation-name: Clouds;
    -ms-animation-duration: 50s;
    -ms-animation-timing-function: linear;
    -ms-animation-iteration-count: infinite;
}

@media only screen and (max-width: 680px) {
  .clouds {
    width: 25%;
    top: 3em;
  }
}

/* Clouds CSS3 animations */

@-webkit-keyframes Clouds {
    from {
        right: -15%;
    }
    to { 
        right: 100%;
        top: 1em;
    }
}
@-moz-keyframes Clouds {
    from {
        right: -15%;
    }
    to { 
        right: 100%;
        top: 1em;
    }
}
@-ms-keyframes Clouds {
    from {
        right: -15%;
    }
    to { 
        right: 100%;
        top: 1em;
    }
}

/* End Clouds CSS3 Animation */

JSFIDDLE

对此的任何意见将不胜感激,如果您需要其他任何信息,请告诉我!

My Portfolio Link

【问题讨论】:

    标签: jquery css svg css-animations


    【解决方案1】:

    基于% 的关键帧应该可以正常工作:JSFIDDLE

    为了便于理解,我将动画分成两部分。

    @-webkit-keyframes Clouds-h {
        from {
            right: -15%;
        }
        to { 
            right: 100%;
        }
    }
    
    @-webkit-keyframes Clouds-v {
        from {
            top: 3em;
        }
        50% {
            top: 2em;
        }
        to {
            top: 3em;
        }
    }
    

    并将它们放在一行中:

    -webkit-animation: Clouds-h 50s linear infinite, Clouds-v 10s ease-in-out infinite;
    

    通过这种方式,您可以轻松地调整动画以制作复杂的动画。就像为云大小添加第三个动画一样。

    【讨论】:

    • 天啊,云大小的第三个动画很巧妙!!我一回家我就会试试这个,但小提琴显示了我需要做的事情,非常感谢!
    • 也感谢您简化代码,因为我写的所有内容都开始看起来很糟糕。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多