图片动态化

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 属性

猜你喜欢

转载自www.cnblogs.com/justSmile2/p/9862625.html