使用CSS3在屏幕上移动图像

Ali*_*ala 6 animation transition image css3

我浏览网络已经有一段时间了,试图找到一种在加载页面时使图标移动到屏幕上的方法(从div的左边到中心)。如何才能做到这一点?

这是我到目前为止的内容:

CSS3

a#rotator {
    text-decoration: none;
    padding-right: 20px;
    margin-left: 20px;
    float: left;
}

a#rotator img {
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out; 
    -o-transition: all 1s ease-in-out; 
    -ms-transition: all 1s ease-in-out; 
    border-radius:60px;
    transition-duration: 1s;
    }

a#rotator img:hover { 
    box-shadow: 0 3px 15px #000;
    -webkit-transform: rotate(360deg); 
    -moz-transform: rotate(360deg); 
    -o-transform: rotate(360deg);
    -ms-transform: rotate(360deg); 
    transform: translate()
}
Run Code Online (Sandbox Code Playgroud)

pab*_*xel 7

如果需要纯CSS解决方案,则可以使用CSS3动画功能。创建或声明动画时,用关键字@animation后跟要赋予该动画的名称。在大括号内,您必须指示动画的关键帧以及该关键帧中将应用哪些CSS属性,以便完成关键帧之间的过渡。您必须至少指定两个关键帧,即动画的开始和结束,并使用关键字fromand to,后跟大括号内的属性。例如:

@keyframes myanimation
{
    from {
        left: 0;
    }
    to {
        left: 50%;
    }
}
Run Code Online (Sandbox Code Playgroud)

或具有三个关键帧的示例(百分比表示持续时间的百分比):

@keyframes myanimation
{
    0% {
        left: 0;
    }
    10% {
        left: 50%;
    }
    100% {
        left: 10%;
    }
}
Run Code Online (Sandbox Code Playgroud)

创建动画后,必须指定要设置动画的元素,它只是animationCSS规则中与该元素匹配的属性。请注意,值中的名称必须与您之前创建的名称以及动画的持续时间匹配。例如:

a#rotator {
    animation: myanimation 5s;
}
Run Code Online (Sandbox Code Playgroud)

在这里,您可以指定持续时间,必须重复的次数等。您可以在此处阅读完整的规格:http : //www.w3.org/TR/css3-animations/

在这里,您可以看到一个使用提供的代码的工作示例:http : //jsfiddle.net/mcSL7/1/

我已经停止浮动该元素,并为其分配了绝对位置,因此可以使用顶部和左侧属性在体内移动它。

几乎所有现代浏览器都支持此CSS功能,即使其中一些浏览器需要-webkit-供应商前缀。在此处检查:http : //caniuse.com/#feat=css-animation