运动函数
作者:互联网
function move(ele, obj, callback) {
let timerLen = 0;
for (let key in obj) {
timerLen++
let speed;
clearInterval(ele[key])
ele[key] = setInterval(() => {
let style;
if (key === 'opacity') {
style = getStyle(ele, key) * 100;
} else {
style = parseInt(getStyle(ele, key));
}
speed = (obj[key] - style) / 25;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); style = style + speed;
if (key === 'opacity') { ele.style[key] = style / 100; } else { ele.style[key] = style + 'px'; }
if (style === obj[key]) { clearInterval(ele[key]); timerLen--; if (timerLen === 0) { callback && callback(); } }
}, 10) } }
function getStyle(ele, attr) { var style; if (ele.currentStyle) { style = ele.currentStyle[attr]; } else { style = window.getComputedStyle(ele)[attr]; } return style }
function compare(prop, align) { return function (a, b) { var value1 = a[prop]; var value2 = b[prop]; if (align == "positive") {//正序 return new Date(value1) - new Date(value2); } else if (align == "inverted") {//倒序 return new Date(value2) - new Date(value1); } } } export { move, compare }
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed); style = style + speed;
if (key === 'opacity') { ele.style[key] = style / 100; } else { ele.style[key] = style + 'px'; }
if (style === obj[key]) { clearInterval(ele[key]); timerLen--; if (timerLen === 0) { callback && callback(); } }
}, 10) } }
function getStyle(ele, attr) { var style; if (ele.currentStyle) { style = ele.currentStyle[attr]; } else { style = window.getComputedStyle(ele)[attr]; } return style }
function compare(prop, align) { return function (a, b) { var value1 = a[prop]; var value2 = b[prop]; if (align == "positive") {//正序 return new Date(value1) - new Date(value2); } else if (align == "inverted") {//倒序 return new Date(value2) - new Date(value1); } } } export { move, compare }
标签:timerLen,function,style,函数,ele,key,运动,speed 来源: https://www.cnblogs.com/wsj1/p/16529825.html