模仿百度首页“元宵节汤圆”动图:(js的定时任务:setinterval)
原理:需要一张切图,通过不断定位使得图片就像一帧一帧的图片在播放从而形成了动画
效果图:

切图地址:
https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png
页面代码:
html>
<meta><script></script> --%>
<title>首页</title><style>
</style><script>
$(function(){ //6210
// 0 270 540 810 1080 1890 2700 2970 3510 3780 4050 4320 5130 5940 6480 7290
// 定时任务,每隔100ms执行一次函数
setInterval("tangyuan()",100);
setInterval("tangyuan1()",100);
//setInterval("indexChange()",1);
});
//汤圆 正着挖
var count = 0;
function tangyuan(){
count = count - 270;
if(count == -8370){
count = 0;
}
var ctxpath = '${ctxpath}';
//url("https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png")
//https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png
$("#tangyuan").css("background","url("+ctxpath+"/img/baidu/baidu_tangyuan.png) "+count+"px"+" 0px no-repeat");
}
//汤圆 倒着挖
var count1 = -8370;
function tangyuan1(){
count1 = count1 + 270;
if(count1 == 0){
count1 = -8370;
}
var ctxpath = '${ctxpath}';
//url("https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png")
//https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png
$("#tangyuan1").css("background","url("+ctxpath+"/img/baidu/baidu_tangyuan.png) "+count1+"px"+" 0px no-repeat");
}
</script>
<span>汤圆我要正着挖(●ˇ∀ˇ●):</span>
<!-- background: url("https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png") -2970px 0px no-repeat; -->
<div>
</div>
<span>汤圆我要倒着挖o(* ̄︶ ̄*)o:</span>
<!-- background: url("https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/img/1519708766000_4f5d68844a93b929405a11d217ef0bf5.png") -2970px 0px no-repeat; -->
<div>
<p>推荐学习:《<a href="https://www.php.cn/course/list/17.html" target="_blank">javascript视频教程</a>》</p>
</div>











