2017-02-07 5 views
2

Polymerを使用して動的にスタイルシートを適用したいと思います。シナリオは、このようなものです:Polymer:動的にスタイルシートを変更する

<link rel="import" href="themes/red.styles.html" /> 
<link rel="import" href="themes/indigo.styles.html" /> 

<dom-module> 
    <style include="indigo-styles"> 
    <template> 
     <div class="header">Header</div> 
     <button on-click="_toggleStylesheet"></button> 
    </template> 
</dom-module> 

<script> 
    Polymer({ 
    _toggleStylesheet: function() { 
     // remove indigo-styles and apply red-styles and so on 
    } 
    }) 
</script> 

これはポリマーで達成することができる方法を誰もが知っていますか? ありがとうございます!

答えて

0

this.updateStylesを使用してPolymer.Elementのスタイルを変更します。

Polymer.updateStyles({ 
    '--property-one': 'var(--paper-red-900)', 
    '--property-two': 'var(--paper-indigo-500)', 
    ... 
    '--property-whatever': 'etc' 
}) 
:グローバル変更を適用するには

使用Polymer.updateStyles

関連する問題