当 "resizable" 元素为 hidden/un-hidden 时,聚合物 IronResizableBehavior 铁调整大小事件未触发,如文档中所述
Polymer IronResizableBehavior iron-resize event not fired when "resizable" element is hidden/un-hidden as described in docs
下面是修改后的 Polymer IronResizableBehavior 演示,它根据隐藏或取消隐藏的 "resizable" 元素触发,而不仅仅是根据调整大小的 window 元素触发。调整 window 大小时会触发该事件,但 Polymer 文档 (https://elements.polymer-project.org/elements/iron-resizable-behavior) 表明:
This event will be fired when they become showing after having been hidden, when they are resized explicitly by another resizable, or when the window has been resized.
因此,我希望当我 hide/un-hide 下面的 "x-puck" 元素时也会触发该事件。我做错了什么?
<link rel="import" href="../../iron-resizable-behavior.html">
<link rel="import" href="../../../paper-button/paper-button.html">
<dom-module id="x-puck">
<style>
</style>
<template>
<b>I'm an un-hidden element!</b>
</template>
</dom-module>
<script>
Polymer({
is: 'x-puck',
behaviors: [
Polymer.IronResizableBehavior
],
listeners: {
'iron-resize': '_onIronResize'
},
attached: function() {
this.async(this.notifyResize, 1);
},
_onIronResize: function() {
alert('x-puck _onIronResize called!');
}
});
</script>
<dom-module id="x-app">
<style>
</style>
<template>
<paper-button on-tap="showElement">Show</paper-button>
<paper-button on-tap="hideElement">Hide</paper-button>
<x-puck id="xPuck" hidden$="{{hide}}"></x-puck>
</template>
</dom-module>
<script>
Polymer({
is: 'x-app',
behaviors: [
Polymer.IronResizableBehavior
],
properties: {
hide: {
type: Boolean,
value: true
}
},
showElement: function() {
this.hide = false;
},
hideElement: function() {
this.hide = true;
}
});
</script>
我快速查看了 IronResizableBehavior
的源代码,没有看到任何支持实现它的元素在其 CCS display
属性 更改时调整大小的内容(本质上就是 hidden
属性的作用)。
查看 iron-pages
元素,you can see that it explicitely calls notifyResize
whenever an element is unhidden,所以我认为这就是它的工作方式。
我建议您打开 an issue on the Github repo 以获得更多反馈,如果我是对的,请更正此误导性陈述。
下面是修改后的 Polymer IronResizableBehavior 演示,它根据隐藏或取消隐藏的 "resizable" 元素触发,而不仅仅是根据调整大小的 window 元素触发。调整 window 大小时会触发该事件,但 Polymer 文档 (https://elements.polymer-project.org/elements/iron-resizable-behavior) 表明:
This event will be fired when they become showing after having been hidden, when they are resized explicitly by another resizable, or when the window has been resized.
因此,我希望当我 hide/un-hide 下面的 "x-puck" 元素时也会触发该事件。我做错了什么?
<link rel="import" href="../../iron-resizable-behavior.html">
<link rel="import" href="../../../paper-button/paper-button.html">
<dom-module id="x-puck">
<style>
</style>
<template>
<b>I'm an un-hidden element!</b>
</template>
</dom-module>
<script>
Polymer({
is: 'x-puck',
behaviors: [
Polymer.IronResizableBehavior
],
listeners: {
'iron-resize': '_onIronResize'
},
attached: function() {
this.async(this.notifyResize, 1);
},
_onIronResize: function() {
alert('x-puck _onIronResize called!');
}
});
</script>
<dom-module id="x-app">
<style>
</style>
<template>
<paper-button on-tap="showElement">Show</paper-button>
<paper-button on-tap="hideElement">Hide</paper-button>
<x-puck id="xPuck" hidden$="{{hide}}"></x-puck>
</template>
</dom-module>
<script>
Polymer({
is: 'x-app',
behaviors: [
Polymer.IronResizableBehavior
],
properties: {
hide: {
type: Boolean,
value: true
}
},
showElement: function() {
this.hide = false;
},
hideElement: function() {
this.hide = true;
}
});
</script>
我快速查看了 IronResizableBehavior
的源代码,没有看到任何支持实现它的元素在其 CCS display
属性 更改时调整大小的内容(本质上就是 hidden
属性的作用)。
查看 iron-pages
元素,you can see that it explicitely calls notifyResize
whenever an element is unhidden,所以我认为这就是它的工作方式。
我建议您打开 an issue on the Github repo 以获得更多反馈,如果我是对的,请更正此误导性陈述。