-2
A
回答
0
這是第一行的動畫。更改y軸將移動圖像以顯示第二行。 PHP或Javascript不是必需的。
.animation {
width: 317px;
height: 174px;
background: url('https://i.stack.imgur.com/xo7T3.jpg') 0 0;
animation: play 16s infinite;
}
@keyframes play {
0% { background-position: 0 0; }
5.99% { background-position: 0 0; }
6% { background-position: -317px 0; }
11.99% { background-position: -317px 0; }
12% { background-position: -634px 0; }
17.99% { background-position: -634px 0; }
18% { background-position: -951px 0; }
23.99% { background-position: -951px 0; }
24% { background-position: -1268px 0; }
99.99% { background-position: -1268px 0; }
100% { background-position: 0 0; }
}
<div class="animation"></div>
0
這是給你一個工作feedle由我。 在JavaScript上實現,使用jQuery庫。
https://jsfiddle.net/271qnqrj/
JS:
(function($) {
$.fn.extend({
mygif: function(speed, width, height, verticalBorderWidth, horizontalBorderWidth) {
speed = speed || 400;
width = width || 315;
height = height || 175;
verticalBorderWidth = verticalBorderWidth || 5;
horizontalBorderWidth = horizontalBorderWidth || 5;
this.each(function() {
var img = $(this).attr('src');
var div = $('<div class="mygif" data-frame="1" style="width: ' + width + 'px;height:' + height + 'px;background-image: url(\'' + img + '\');"/>').insertAfter($(this));
$(this).remove();
});
window.setInterval(function() {
$('.mygif').each(function() {
var frame = $(this).data('frame');
if (frame == 16) {
frame = 1;
} else {
frame++;
}
$(this).data('frame', frame);
var posX = (width + verticalBorderWidth) * ((frame-1) % 4);
var posY = (height + horizontalBorderWidth) * (Math.floor((frame-1)/4));
$(this).css('background-position', -posX + 'px ' + -posY + 'px');
});
}, speed);
}
});
$('.mygif').mygif()
})(jQuery);
HTML:
<img src="https://i.stack.imgur.com/xo7T3.jpg" class="mygif" />
CSS:
img.mygif { display: none; }
相關問題
- 1. 將wmz文件轉換爲gif或jpg
- 2. PIL - 轉換GIF幀爲JPG
- 3. CodeIgniter - 將GIF轉換爲JPG?可能?
- 4. ImageMagick將jpg圖像轉換爲gif慢
- 5. 使用Imagemagick將GIF,PNG和JPG轉換爲.ICO文件
- 6. 將文檔轉換爲Jpg
- 7. WinRT的轉換JPG或PNG爲GIF
- 8. 將2頁.tif文件轉換爲.jpg
- 9. Android NDK:將.jpg轉換爲.bmp文件
- 10. 將ppt或pptx文件轉換爲jpg
- 11. 將tiff文件從php轉換爲jpg
- 12. 將jp2的byte []轉換爲jpg文件
- 13. 將IRestResponse轉換爲「image/jpg」文件
- 14. 如何將HTML文件轉換爲GIF
- 15. 將SWF轉換爲GIF文件
- 16. 將GIF轉換爲CUR文件
- 17. 爲什麼我從gif文件轉換的jpg文件不夠清晰?
- 18. PIL將PNG或GIF轉換爲JPG格式,無需使用
- 19. 如何將圖像(GIF,JPG,JPEG,PNG)轉換爲PHP中的TIFF?
- 20. 將bmp/gif/png/etc轉換爲jpg的公共服務?
- 21. 如何將dicom文件轉換爲jpg轉換
- 22. 將.eps轉換爲.jpg
- 23. 將DCOM轉換爲JPG
- 24. 將.jpg轉換爲pdf
- 25. 將TXT轉換爲JPG
- 26. c#將HTML轉換爲JPG
- 27. 將JPG轉換爲HTML
- 28. 將GIF轉換爲MOV IOS
- 29. 將jpg文件轉換爲映射文件
- 30. Ghostscript將pdf轉換爲jpg,保存文件或臨時文件?
作爲'gif'具體而言,不是用CSS,而是作爲一次顯示一個圖像的動畫,而不是用jquery/css。如果所有合成圖像的尺寸相同/部件位於同一位置,則它只是一個帶有溢出隱藏的div,並將邊距設置爲偏移到每個圖像。 –
你手裏有示例代碼嗎? – rootist
我現在不能給你工作代碼,但基本上'