angular - Edge & IE 不尊重角度动画中的溢出-y
问题描述
我为我的应用程序制作了以下角度动画,以便能够垂直展开/折叠元素。它可以工作,但似乎 Edge 和 IE 在动画期间不应用overflow-y
它,这使它看起来很不稳定。
import { trigger, transition, style, animate, state } from '@angular/animations';
export const expandCollapseAnimation = trigger('expandCollapse', [
state('*', style({
height: '*',
})),
state('void', style({
height: '0',
'overflow-y': 'hidden',
})),
//Same transition duration/easing when entering or leaving
transition('* => *', animate(`300ms cubic-bezier(0.4, 0, 0.2, 1)`))
]);
这是它在 Chrome 中的样子,overflow-y
正确应用的地方
这就是它在 Edge 和 IE 中的样子,其中内容“弹出”进出。
我能做些什么来解决这个问题?
是的,我确实安装并添加web-animations-js
到我的 Polyfills 文件中,这并没有改变任何东西
解决方案
这是一种解决方法,但它至少会在 IE/Edge 中制作类似的动画。它相似,但不完全相同,并且没有任何溢出问题。
事实证明这是一个 Angular 问题。它尝试将动画代码转换@keyframes
为不支持的浏览器的 CSS,WebAnimations
并且该overflow-y
属性似乎无法正确转换。
因为我们知道什么是不支持的,所以我们可以检测对 API 的支持并根据它切换出要使用的动画。该行将'animate' in document.documentElement
告诉我们是否WebAnimations
支持。
这是完整的代码:
import { trigger, transition, style, animate, state, AnimationMetadata } from '@angular/animations';
import { defaultDuration, defaultEasing } from './animation-variables';
//Angular does not properly translate a WebAnimation with `overflow-y` into a CSS Animation, this it overflows it's container.
//So we use an entirely different animation for these browsers. It will still overflow, but the added opacity transition makes it less obvious
const animForWebAnimations: AnimationMetadata[] = [
state('*', style({
height: '*',
})),
state('void', style({
height: '0',
'overflow-y': 'hidden',
})),
//Same transition duration/easing when entering or leaving
transition('* => *', animate(`${defaultDuration}ms ${defaultEasing}`))
];
const animForCssAnimations: AnimationMetadata[] = [
state('*', style({
height: '*',
'transform-origin': 'center 0',
transform: 'scaleY(1)'
})),
state('void', style({
height: '0px',
'transform-origin': 'center 0',
transform: 'scaleY(0)'
})),
transition('* => *', animate(`${defaultDuration}ms ${defaultEasing}`))
];
const expandCollapseAnimationMetadata = 'animate' in document.documentElement ? animForWebAnimations : animForCssAnimations;
export const expandCollapseAnimation = trigger('expandCollapse', expandCollapseAnimationMetadata);
对于 Chrome/Firefox 和其他“好”浏览器,动画在我的问题中看起来与上面相同,但现在在 IE/Edge 中看起来像这样
推荐阅读
- python - tensorflow 2 keras shuffle each row gradient problem
- javascript - 无法在嵌套的 shadowdom 中使 div/元素可移动
- excel - 向下拖动公式时,每隔一段时间跳过一行
- webpack - Webpack SCSS 和 Babel 配置问题
- angular6 - 如何在 Angular 6 上捕获 SignalR 响应
- snowflake-cloud-data-platform - Snowflake 中是否有办法允许用户在程序上获取 ddl 但没有使用或所有权权限?
- c - C: malloc() 访问内存中的禁止位置导致代码崩溃
- facebook-graph-api - 是什么导致这两个 Facebook 用户在扩展页面访问令牌时收到不同的结果?
- c# - Linq to Entity 使用方法语法从左表和右表的 0 或 1 返回记录?
- java - Filters.geoIntersects 从 Java 应用程序不返回任何内容,而来自 Robo 3T 的查询返回一些