本帖最后由 rexuegg123 于 2021-12-26 14:36 编辑
let obj = { targetId:值为字符(表示父级元素id), time:值为数字(表示动画显示的整体时间,单位毫秒), picName:值为字符(大图名称及后缀), picSrc:值为字符(表示大图路径), width:值为数组(如[192,5],0号元素表示小图的宽,1号元素表示大图每排有几张小图), height:值为字符(表示大图路径及文件名称), width:值为数组(如[192,5],0号元素表示小图的高,1号元素表示大图每列有几张小图), top:-20, left:-20, per:值为数字(表示显示比例) } function 帧动画显示 (obj) { let id = obj.targetId+'_'+obj.picName; let z = '<div id="'+id+'"><img id="'+id+'_img"></div>'; $('#'+obj.targetId).append(z); let div = document.getElementById(id); div.style.position = 'absolute'; div.style.top = obj.top+'px'; div.style.left = obj.left+'px'; div.style.width = obj.width[0]*obj.per/100+'px'; div.style.height = obj.height[0]*obj.per/100+'px'; div.style.overflow = 'hidden'; var img = document.getElementById(id+'_img'); img.style.position = 'absolute'; img.style.top = '0px'; img.style.left = '0px'; img.style.width = obj.width[0]*obj.width[1]*obj.per/100+'px'; img.style.height = obj.height[0]*obj.height[1]*obj.per/100+'px'; img.src = obj.picSrc+obj.picName;// '/img/……/num.png' var w = obj.width[0]*obj.per/100, h = obj.height[0]*obj.per/100; var wt = obj.width[1], ht = obj.height[1]; var picnum = wt*ht; //横向张数*纵向张数 var pickeep = obj.time/picnum; var i=2; function AnimateOfSkill_demo () { if (i<picnum) { img.style.top = -(i<=wt ? 0 : (Math.ceil(i/wt)-1)) * h + 'px'; img.style.left = -(i-(Math.ceil(i/wt)-1) * wt-1) * w + 'px'; i++; setTimeout(function(){ AnimateOfSkill_demo () },pickeep); } else {div.remove()}; }; setTimeout(function(){ AnimateOfSkill_demo () },pickeep); }
let obj =
{
targetId:值为字符(表示父级元素id),
time:值为数字(表示动画显示的整体时间,单位毫秒),
picName:值为字符(大图名称及后缀),
picSrc:值为字符(表示大图路径),
width:值为数组(如[192,5],0号元素表示小图的宽,1号元素表示大图每排有几张小图),
height:值为字符(表示大图路径及文件名称),
width:值为数组(如[192,5],0号元素表示小图的高,1号元素表示大图每列有几张小图),
top:-20,
left:-20,
per:值为数字(表示显示比例)
}
function 帧动画显示 (obj) {
let id = obj.targetId+'_'+obj.picName;
let z = '<div id="'+id+'"><img id="'+id+'_img"></div>';
$('#'+obj.targetId).append(z);
let div = document.getElementById(id);
div.style.position = 'absolute';
div.style.top = obj.top+'px';
div.style.left = obj.left+'px';
div.style.width = obj.width[0]*obj.per/100+'px';
div.style.height = obj.height[0]*obj.per/100+'px';
div.style.overflow = 'hidden';
var img = document.getElementById(id+'_img');
img.style.position = 'absolute';
img.style.top = '0px';
img.style.left = '0px';
img.style.width = obj.width[0]*obj.width[1]*obj.per/100+'px';
img.style.height = obj.height[0]*obj.height[1]*obj.per/100+'px';
img.src = obj.picSrc+obj.picName;// '/img/……/num.png'
var w = obj.width[0]*obj.per/100, h = obj.height[0]*obj.per/100;
var wt = obj.width[1], ht = obj.height[1];
var picnum = wt*ht; //横向张数*纵向张数
var pickeep = obj.time/picnum;
var i=2;
function AnimateOfSkill_demo () {
if (i<picnum) {
img.style.top = -(i<=wt ? 0 : (Math.ceil(i/wt)-1)) * h + 'px';
img.style.left = -(i-(Math.ceil(i/wt)-1) * wt-1) * w + 'px';
i++;
setTimeout(function(){ AnimateOfSkill_demo () },pickeep);
} else {div.remove()};
};
setTimeout(function(){ AnimateOfSkill_demo () },pickeep);
}
根据你的情况,看是否适合你。 |