CSS background-image slideshow

后端 未结 4 1633
时光说笑
时光说笑 2020-12-08 05:57

I am pretty new to CSS and HTML, but I am learning the ropes. Right now, I have a background image on my header section and I am trying to turn this into a slideshow with 3-

4条回答
  •  粉色の甜心
    2020-12-08 06:45

    Made modifications to this answer.

    http://jsfiddle.net/qyVMj/

    #graphic:before {
        content: '';
        position: absolute;
        width: 400%;
        height: 100%;
        z-index: -1;
        background: url(http://placekitten.com/500/500/) repeat; /* Image is 500px by 500px, but only 200px by 50px is showing. */
        animation: slide 3s infinite;
    }
    @keyframes slide {
        20% {
            left: 0;
        }
        40%, 60% {
            left: -50%;
        }
        80%, 100% {
            left: -100%;
        }
    }
    

    Bascially, just make your image into a sprite (combine them into 1 file), then use left: to cycle thru them. (Of course modify the left and percent values to your liking)

提交回复
热议问题