您需要使用画布元素和 javascript 创建动画,然后在检测到某些动作时更改图像
html:
<canvas id="#test" data-url="...url..."></canvas>
jQuery:
$(document).ready(function(){
$('#test').each(function(index, element){
var obj = $(this);
var canvas = $(this)[0];
var context = element.getContext('2d');
var img = new Image();
img.src = $(this).data('url');
img.onload = function () {
context.drawImage(img, 0, 0);
};
$(this).on({
"mouseover" : function() {
canvas.width = canvas.width;
context.drawImage(img, img.width / 2,0,img.width / 2,img.height,0,0,img.width / 2,img.height);
},
"mouseout" : function() {
canvas.width = canvas.width;
context.drawImage(img, 0, 0);
}
});
});
此示例加载 2 图像水平精灵,当您移动图像时,它会从前半部分更改为后半部分,对于您的应用程序,您需要加载许多精灵然后更改它们
您还可以使用 jquery 插件制作动画,例如http://spritely.net/