Polymer 1.0 dom-if 模板从内部 div 样式中移除显示
Polymer 1.0 dom-if template removes display from inner div style
请考虑以下平板支撑:
http://embed.plnkr.co/O3xz1m/preview
http://embed.plnkr.co/Ajh2Nm/preview
第一个在屏幕中央显示 xxx(仅在 chrome 中),而第二个显示 xxx 未居中。看起来这是因为
<template is="dom-if" if="true">
在第二个例子中。据我了解 display: flex 只是以某种方式从有效页面中删除。为什么?
此致,尤金。
默认情况下,dom-if
hides its contents when if
becomes falsy as a performance optimization. It achieves this by setting style.display = 'none'
on the stamped children. It currently does not save the previous value of display, so it gets set back to ''
on truthy, hence the previous flex
value is lost; We will plan on fixing that behavior against the issue you opened here: https://github.com/Polymer/polymer/issues/2037.
在此期间,您可以
- 使用 class(与内联样式相反)将
display: flex
应用于模板的直接子项,或
- 在
dom-if
上使用 restamp
属性来避免隐藏行为(还有其他权衡:性能,您可以在上面链接的 dom-if
文档中阅读)。
请考虑以下平板支撑:
http://embed.plnkr.co/O3xz1m/preview
http://embed.plnkr.co/Ajh2Nm/preview
第一个在屏幕中央显示 xxx(仅在 chrome 中),而第二个显示 xxx 未居中。看起来这是因为
<template is="dom-if" if="true">
在第二个例子中。据我了解 display: flex 只是以某种方式从有效页面中删除。为什么?
此致,尤金。
默认情况下,dom-if
hides its contents when if
becomes falsy as a performance optimization. It achieves this by setting style.display = 'none'
on the stamped children. It currently does not save the previous value of display, so it gets set back to ''
on truthy, hence the previous flex
value is lost; We will plan on fixing that behavior against the issue you opened here: https://github.com/Polymer/polymer/issues/2037.
在此期间,您可以
- 使用 class(与内联样式相反)将
display: flex
应用于模板的直接子项,或 - 在
dom-if
上使用restamp
属性来避免隐藏行为(还有其他权衡:性能,您可以在上面链接的dom-if
文档中阅读)。