css3 keyframes not working in chrome

2019-08-28 18:53发布

问题:

For some reason the following code doesn't work in Chrome but in Firefox it does:

p.subtitle{
    margin-top:9px;
    font-size:15px;
    font-family: 'din_mediumregular',Arial, Helvetica, sans-serif;
}

a:hover .option-wrapper p.subtitle{
    -webkit-animation: moveFromRight 600ms ease;
    -moz-animation: moveFromRight 600ms ease;   
    -o-animation: moveFromRight 600ms ease; 
    animation: moveFromRight 600ms ease;        
}


@-webkit-keyframes moveFromRight{
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0%);
    }
}

@-moz-keyframes moveFromRight{
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0%);
    }
}

@-o-keyframes moveFromRight{
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0%);
    }
}

@keyframes moveFromRight{
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0%);
    }
}

Is there something wrong with the code? As you can see it includes -webkit-animation and @-webkit-keyframes so I'm unsure.

回答1:

It should be

@-webkit-keyframes moveFromRight{
    from {
        -webkit-transform: translateX(100%);
    }
    to {
        -webkit-transform: translateX(0%);
    }
}


回答2:

Had the same problem but it was due to not adding the iteration count separately

-webkit-animation-name: spin;
-webkit-animation-duration: 4000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;

Didn't work:

-webkit-animation:turning_ccw 4s infinite;