1. 程式人生 > >圖片動態化

圖片動態化

get var 圖片 tint ref clas com ack scrip

1. html

<div class="image-gif"></div>

2. css

<style type="text/css"> .image-gif { width: 200px; height: 300px; background: url(image-gif.jpg); background-position: 0px 0px; } </style>

3. js

<script> var imageGif = document.querySelector(".image-gif"); var left = 0, pos; setInterval(function () { left = left == 1600 ? 0 : left + 200; pos = -left + "px 0px"; imageGif.style.backgroundPosition = pos; }, 100); </script>

CSS background-position 屬性

圖片動態化