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

前端 未结 3 1612
栀梦
栀梦 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:41

    Checkout this example:

    #content {
      height: 300px;
      text-align: center;
      font-size: 26px;
      color: #000;
      position:relative;
    }
    .bg{
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      z-index: -1;
      background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
      animation-name: MOVE-BG;
      animation-duration: 100s;
      animation-timing-function: linear;
      animation-iteration-count: infinite;
    }
    @keyframes MOVE-BG {
       from {
         transform: translateX(0);
       }
       to { 
         transform: translateX(-187%);
       }
    }
    Foreground content

    http://jsfiddle.net/5pVr4/4/

提交回复
热议问题