css3中图像的动画

时间:2013-02-21 13:15:54

标签: html5 css3

我想更改背景图片的不透明度(两张图片相同),但更改应为30 to 45 degree

此外,这会将front image设为background image,然后再backgroung imagefront image

两张图片是:

enter image description hereenter image description here

我希望动画就像显示第一张图像一样,经过一段时间后会显示,但它的高度应该从图像的0到最大高度增长。动画也应该是角度30 degree

我使用了代码

HTML:

    <div class="img_shake">          
        <img id="img_shake" src="img_shake.png" alt="img_shake">    
    </div>

    <div id="div_img_shake_patchwork">
        <img id="img_shake_patchwork" src="img_shake_patchwork.png" alt="img_shake_patchwork">  
    </div>
</div>

CSS:

#main-container{
    position: relative;
    top:0%;
    left:0%;
    height: 480px;
    width: 320px;   
    overflow: hidden;       
    background-size: 100% 100%;
    background-position: center center; 
    opacity:1;
}


#img_shake {
    position: absolute;
    right: 27%;
    opacity: 0;
    top: 27%;
    z-index:2;
}
@-webkit-keyframes img_shake_anim
{
    from {right:-30%;}
    to {right:27%;}
}

@-webkit-keyframes img_shake_anim_again
{
    from {left:27%}
    to {left:0%}
}
@-webkit-keyframes img_shake_fade_in
{
   0%    {opacity:0;}
   100%  {opacity:1;} 
}


#img_shake_patchwork {
    width:100%;
}


#div_img_shake_patchwork
{
    position:absolute;
    top:27%;
    right:27%;  
    overflow : hidden;
    z-index:2;
    height:277px;
    opacity:0;
}

@-webkit-keyframes div_img_shake_patchwork_anim
{
   0%    {height:0;opacity:1;/*-webkit-transform: rotate(-30deg);*/}  
   100%  {height:277px;opacity:1;/*-webkit-transform: rotate(0deg);*/} 
}

2 个答案:

答案 0 :(得分:1)

background-image不会进行转换。您需要使用position: absolutez-index将一个图像放在另一个图像的顶部。然后,您可以转换顶部图片的opacity

答案 1 :(得分:0)

通过更改样式可以完成:

#img_shake_patchwork {
    width:148px;/*Width of Image*/
    -webkit-transform: rotate(30deg);
    left: 22%;
    position: absolute;
    top: 0%;
}

#div_img_shake_patchwork
{
    position:absolute;
    top:26%;
    left:6%;  
    overflow : hidden;
    z-index:2;
    height:277px;/*Height of Image*/
    opacity:0;
    width:296px;/*Double width of Image*/
    -webkit-transform: rotate(-30deg);
}

@-webkit-keyframes div_img_shake_patchwork_anim
{
   0%    {height:0;opacity:1;left:-16% ;top:30%; }  
   100%  {height:277px;opacity:1;left:6%; top:26%; /*-webkit-transform: rotate(0deg);*/} 
}