我包括使用<style include="style-name"></style>
的樣式,它通常工作正常。聚合物:加載動態內容時的重新加載樣式
但是,我有一個元素,它通過JavaScript動態加載和更改其內容。它會在某些時候從外部來源加載新內容並相應地更新其內容。這些新內容沒有應用於它們的style-name
的樣式。
如何獲得Polymer重新評估樣式,並將其應用於新內容?
我正在使用Meteor + Synthesis如果這有所作爲。
我包括使用<style include="style-name"></style>
的樣式,它通常工作正常。聚合物:加載動態內容時的重新加載樣式
但是,我有一個元素,它通過JavaScript動態加載和更改其內容。它會在某些時候從外部來源加載新內容並相應地更新其內容。這些新內容沒有應用於它們的style-name
的樣式。
如何獲得Polymer重新評估樣式,並將其應用於新內容?
我正在使用Meteor + Synthesis如果這有所作爲。
爲了保持風格的範圍,你應該使用聚合物importHref()和和DOM()函數是這樣的:
// ...
let importSource = Polymer.Base.importHref('path/to/external-source',
// Import is done, use the body of that
event => {
// #container is my element which should have the content
// but you can change to any element what you want
// or use just the this.root
Polymer.dom(this.$.container).innerHTML = importSource.import.body;
},
// Handle errors
event => console.error(event));
// ...
這樣,如果你使用的黑幕DOM聚合物將應用該樣式範圍,在影子DOM它應該在默認情況下工作,但我沒有測試,所以更好地使用內置的功能聚合物。
的Polymer.updateStyles()
只有工作,當你改變本地DOM CSS變量是這樣的:this.customStyle['--my-toolbar-color'] = 'blue';
你嘗試調用'Polymer.updateStyles()'或'this.updateStyles()'? 查看[這裏](http://stackoverflow.com/questions/30854101/change-style-programmatically)瞭解更多信息 –