掉落对象的动画无法在IE上运行

时间:2018-09-21 05:02:18

标签: javascript jquery html sass

我对掉入div内的物体有一种幻想。我在所有浏览器中对其进行了测试,并且可以正常工作,但是在IE上它根本没有动画。我要求您的帮助,谢谢!

它既适用于台式机尺寸,也适用于移动设备,除了IE之外,还适用于Google Chrome,Mozilla,Edge,Safarri,Opera

这是我的SCSS代码:

   .falling__Object span {
        display: inline-block;
        z-index: 10000;
        -webkit-animation: falling__Object 10s infinite linear;
        -moz-animation: falling__Object 10s infinite linear;

        &.leaves {
            width: 5vw;
            background: url(../img/section-countdown/leaf.png);
            background-repeat: no-repeat;
            background-size: 75%;
            /* margin: -280px 84px 54px -34px; 

            @media screen and (min-width: 320px) and (max-width:500px) {
                width: 5vwvw;
            }*/
        }

        &.snow {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/snow.gif");
            background-size: 70%;
            background-repeat: no-repeat;
        }

        &.green-leaf {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/green-leaf.png");
            background-size: 70%;
            background-repeat: no-repeat;
        }

        &.spring {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/spring-leaf.png");
            background-size: 70%;
            background-repeat: no-repeat;
        }
    }

    .falling__Object span:nth-child(1n+5) {
        -webkit-animation-delay: 1.3s;
        -moz-animation-delay: 1.3s;
    }

    .falling__Object span:nth-child(3n+2) {
        -webkit-animation-delay: 1.5s;
        -moz-animation-delay: 1.5s;
    }

    .falling__Object span:nth-child(2n+5) {
        -webkit-animation-delay: 1.7s;
        -moz-animation-delay: 1.7s;
    }

    .falling__Object span:nth-child(3n+10) {
        -webkit-animation-delay: 2.7s;
        -moz-animation-delay: 2.7s;
    }

    .falling__Object span:nth-child(7n+2) {
        -webkit-animation-delay: 3.5s;
        -moz-animation-delay: 3.5s;
    }

    .falling__Object span:nth-child(4n+5) {
        -webkit-animation-delay: 5.5s;
        -moz-animation-delay: 5.5s;
    }

    .falling__Object span:nth-child(3n+7) {
        -webkit-animation-delay: 8s;
        -moz-animation-delay: 8s;
    }

    @-webkit-keyframes falling__Object {
        0% {
            opacity: 1;
            -webkit-transform: translate(0, 0px) rotateZ(0deg);
        }

        75% {
            opacity: 1;
            -webkit-transform: translate(100px, 600px) rotateZ(270deg);
        }

        100% {
            opacity: 0;
            -webkit-transform: translate(150px, 800px) rotateZ(360deg);
        }
    }

    @-moz-keyframes falling__Object {
        0% {
            opacity: 1;
            -webkit-transform: translate(0, 0px) rotateZ(0deg);
        }

        75% {
            opacity: 1;
            -webkit-transform: translate(100px, 600px) rotateZ(270deg);
        }

        100% {
            opacity: 0;
            -webkit-transform: translate(150px, 800px) rotateZ(360deg);
        }
    }

这是脚本:

function getSeason() {
    var currentMonth = new Date().getMonth() + 1;
    if (currentMonth === 12 || currentMonth === 1 || currentMonth === 2) {
        $(".falling__Object span").addClass("snow");
    } else if (currentMonth >= 3 && currentMonth <= 5) {
        $(".falling__Object span").addClass("spring");
    } else if (currentMonth >= 6 && currentMonth <= 8) {
        $(".falling__Object span").addClass("green-leaf");
    } else if (currentMonth >= 9 && currentMonth <= 11) {
        $(".falling__Object span").addClass("leaves");
    }
    return ""
}

1 个答案:

答案 0 :(得分:3)

使用与ie11(无前缀)兼容的css属性进行动画,变换和关键帧

.falling__Object span {
        display: inline-block;
        z-index: 10000;
        -webkit-animation: falling__Object 10s infinite linear;
        -moz-animation: falling__Object 10s infinite linear;
        animation: falling__Object 10s infinite linear;

        &.leaves {
            width: 5vw;
            background: url(../img/section-countdown/leaf.png);
            background-repeat: no-repeat;
            background-size: 75%;
            /* margin: -280px 84px 54px -34px; 

            @media screen and (min-width: 320px) and (max-width:500px) {
                width: 5vwvw;
            }*/
        }

        &.snow {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/snow.gif");
            background-size: 70%;
            background-repeat: no-repeat;
        }

        &.green-leaf {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/green-leaf.png");
            background-size: 70%;
            background-repeat: no-repeat;
        }

        &.spring {
            width: 5vw;
            margin: -280px 84px 54px -34px;
            background: url("../img/section-countdown/spring-leaf.png");
            background-size: 70%;
            background-repeat: no-repeat;
        }
    }

    .falling__Object span:nth-child(1n+5) {
        -webkit-animation-delay: 1.3s;
        -moz-animation-delay: 1.3s;
        animation-delay: 1.3s;
    }

    .falling__Object span:nth-child(3n+2) {
        -webkit-animation-delay: 1.5s;
        -moz-animation-delay: 1.5s;
        animation-delay: 1.5s;
    }

    .falling__Object span:nth-child(2n+5) {
        -webkit-animation-delay: 1.7s;
        -moz-animation-delay: 1.7s;
        animation-delay: 1.7s;
    }

    .falling__Object span:nth-child(3n+10) {
        -webkit-animation-delay: 2.7s;
        -moz-animation-delay: 2.7s;
        animation-delay: 2.7s;
    }

    .falling__Object span:nth-child(7n+2) {
        -webkit-animation-delay: 3.5s;
        -moz-animation-delay: 3.5s;
        animation-delay: 3.5s;
    }

    .falling__Object span:nth-child(4n+5) {
        -webkit-animation-delay: 5.5s;
        -moz-animation-delay: 5.5s;
        animation-delay: 5.5s;
    }

    .falling__Object span:nth-child(3n+7) {
        -webkit-animation-delay: 8s;
        -moz-animation-delay: 8s;
        animation-delay: 8s;
    }

    @-webkit-keyframes falling__Object {
        0% {
            opacity: 1;
            -webkit-transform: translate(0, 0px) rotateZ(0deg);
            transform: translate(0, 0px) rotateZ(0deg);
        }

        75% {
            opacity: 1;
            -webkit-transform: translate(100px, 600px) rotateZ(270deg);
            transform: translate(100px, 600px) rotateZ(270deg);
        }

        100% {
            opacity: 0;
            -webkit-transform: translate(150px, 800px) rotateZ(360deg);
            transform: translate(150px, 800px) rotateZ(360deg);
        }
    }

    @-moz-keyframes falling__Object {
        0% {
            opacity: 1;
            -webkit-transform: translate(0, 0px) rotateZ(0deg);
            transform: translate(0, 0px) rotateZ(0deg);
        }

        75% {
            opacity: 1;
            -webkit-transform: translate(100px, 600px) rotateZ(270deg);
            transform: translate(100px, 600px) rotateZ(270deg);
        }

        100% {
            opacity: 0;
            -webkit-transform: translate(150px, 800px) rotateZ(360deg);
            transform: translate(150px, 800px) rotateZ(360deg);
        }
    }
    @keyframes falling__Object {
        0% {
            opacity: 1;
            -webkit-transform: translate(0, 0px) rotateZ(0deg);
            transform: translate(0, 0px) rotateZ(0deg);
        }

        75% {
            opacity: 1;
            -webkit-transform: translate(100px, 600px) rotateZ(270deg);
            transform: translate(100px, 600px) rotateZ(270deg);
        }

        100% {
            opacity: 0;
            -webkit-transform: translate(150px, 800px) rotateZ(360deg);
            transform: translate(150px, 800px) rotateZ(360deg);
        }
    }