Polymer:如何动态处理样式 [英] Polymer: how to handle a style dynamically

查看:62
本文介绍了Polymer:如何动态处理样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试创建一个简单的拖放.是否可以动态设置元素样式.我的代码会更明确:

Hey i'm trying to create a simple drag and drop. Is that possible to style an element dynamically. My code will be more explicit:

<link rel="import" href="../bower_components/polymer/polymer.html">

<dom-module id="wireframe-view">
<template>
    <div on-tap="handleTap"
        style$=width:{{ width }}px; background-color:red;
     >Hello, World</div>    
</template>    


<script>    
    Polymer({
        is: "wireframe-view",
        handleTap: function() {
           this.width = 200;
        }
    });

</script>

这应该会改变我的样式"属性中的宽度:/

This should change the width in my "style" propertie :/

推荐答案

如果属性值包含空格,则需要引号.

If the property value contains spaces quotes are required.

style$="width:{{ width }}px; background-color:red";

这篇关于Polymer:如何动态处理样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆