我一直在关注aCSS Tricks article on animating section height并且我想在我的Agnular 2应用程序中使用的解决方案具有以下用于节扩展的功能:
expandSection(element) {
// get the height of the element's inner content, regardless of its actual size
var sectionHeight = element.scrollHeight;
// have the element transition to the height of its inner content
element.style.height = sectionHeight + 'px';
// when the next css transition finishes (which should be the one we just triggered)
element.addEventListener('transitionend', function (e) {
console.log(arguments)
// remove this event listener so it only gets triggered once
element.removeEventListener('transitionend', arguments.callee);
// remove "height" from the element's inline styles, so it can return to its initial value
element.style.height = null;
});
}
arguments.callee
行抛出一个错误:异常:TypeError:“caller”、“callee”和“arguments”属性
不能在严格模式函数或参数对象上访问
给他们打电话
有人能为我提供一个解决办法吗?
最佳答案
可以显式声明函数:
expandSection(element) {
// get the height of the element's inner content, regardless of its actual size
var sectionHeight = element.scrollHeight;
// have the element transition to the height of its inner content
element.style.height = sectionHeight + 'px';
function myFunc(e) {
console.log(arguments)
// remove this event listener so it only gets triggered once
element.removeEventListener('transitionend', myFunc);
// remove "height" from the element's inline styles, so it can return to its initial value
element.style.height = null;
}
// when the next css transition finishes (which should be the one we just triggered)
element.addEventListener('transitionend', myFunc);
}