【发布时间】:2019-02-21 17:51:27
【问题描述】:
所以动态设置样式很容易,我的问题是基于媒体查询中的动态样式,所以在 max-width: 1000px 之间,我希望样式是基于属性或一些计算的 JS 的东西,比如总轮播的宽度取决于组件的数量。
无论如何,这里有一段代码 sn-p,它不起作用,但显示了我对如何应用这些属性的想法:-P
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<dom-module id="hello-eggs">
<template>
<style>
:host {
display: block;
background: [[prop2]];
}
@media screen and (max-width: 1000px) {
background: [[prop2]]
}
</style>
<span>[[prop1]] are here</span>
</template>
<script>
/**
* @customElement
* @polymer
*/
class HelloEggs extends Polymer.Element {
static get is() { return 'hello-eggs'; }
static get properties() {
return {
prop1: {
type: String,
value: 'Hello Eggs'
},
prop2: {
type: String,
value: '#fc0'
}
};
}
}
window.customElements.define(HelloEggs.is, HelloEggs);
</script>
</dom-module>
提前谢谢你
【问题讨论】:
标签: css polymer-2.x shadow-dom