简体   繁体   English

如何使用Javascript + CSS分割图像?

[英]How to split the image using Javascript + CSS?

I have the image like this: 我的图像是这样的:

替代文字

I want to split it into six squares, and I can keep looping to display the animation. 我想把它分成六个方块,我可以继续循环来显示动画。 Do you have any ideas to split the image by JS + CSS instead of using 6 separate image files. 您是否有任何想法通过JS + CSS分割图像而不是使用6个单独的图像文件。

Set it as a background image and manipule the background position. 将其设置为背景图像并操纵背景位置。

Update: As seth mentioned, the technique is called CSS Sprites. 更新:如上所述,该技术称为CSS Sprites。 Searching google for animation with css sprites turns up some good results. 使用css sprites搜索谷歌动画会产生一些好的结果。

这是SitePoint关于使用jQuery的精灵动画的一篇文章

There are at least two techniques 至少有两种技术

  • Use image as background 使用图像作为背景
  • Use CSS clip 使用CSS剪辑

Here is a good example of use of first technique. 是使用第一种技术的一个很好的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM