对于 JavaScript“类”,我有几个几乎相同的 CSS 动画函数。我在下面发布的是高度,但我也有一些宽度、左侧等。对我来说,对于基本相同的任务有不同的功能似乎相当多余,我可以用一些替换下面函数中的高度吗什么样的 CSS 属性参数?
WindowItem.prototype.animateHeight = function(inElement, inTarget) {
var selfCall = true;
var currHeight = parseInt(inElement.style.height, 10);
if (this.isExpanded) {
if (currHeight < inTarget) {
currHeight += ((inTarget-currHeight)>>3)+1;
if (currHeight >= inTarget) {
currHeight = inTarget;
selfCall = false;
}
}
}
else {
if (currHeight > inTarget) {
currHeight -= ((currHeight-inTarget)>>3)+1;
if (currHeight <= inTarget) {
currHeight = inTarget;
selfCall = false;
}
}
}
inElement.style.height = currHeight+"px";
if (selfCall) {
var self = this;
setTimeout(function() {
self.animateHeight(inElement, inTarget);
}, 33);
}
}
编辑:我可能还应该发布我是如何调用它的,我不确定在这个例子中要传递什么函数来指定高度:this.animateHeight(this.imgWindow, 0);