Animate CSS background-position with smooth results (sub-pixel animation)

前端 未结 3 1623
栀梦
栀梦 2020-12-01 02:17

I\'m trying to animate the background-position of a div, slowly, but without it having jerky movement. You can see the result of my current efforts here:

http://jsf

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 02:48

    You should adjust your HTML and CSS little bit

    Working Demo

    HTML

    Foreground content

    CSS

    @-webkit-keyframes MOVE-BG {
        from { left: 0; }
        to { left: -2000px; }
    }
    
    #wrapper {
        position:relative;
        width:800px;
        height: 300px;
        overflow:hidden;
    }
    
    #page {
        text-align: center;
        font-size: 26px;
        color: #000;
    }
    
    #content {
        width: 2000px;
        height: 300px;
        background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
        position:absolute;
        top: 0;
        left: 0;
        z-index:-1;
        -webkit-animation-name: MOVE-BG;
        -webkit-animation-duration: 100s;
        -webkit-animation-timing-function: linear;
        -webkit-animation-iteration-count: infinite;
    }
    

提交回复
热议问题