Polymer 1.x:造纸厂提升不起作用?

Polymer 1.x: paper-fab elevation not working?

In this jsBin,我正在尝试向我的元素添加 paper-fab

我希望看到对应于 elevation 属性 的影子。但是我没有看到影子。所有的高程似乎都有相同的阴影(隐含的 z 深度)。

是我的代码有问题还是元素有问题?

http://jsbin.com/corisahoqi/edit?html,输出
<!doctype html>
<head>
  <meta charset="utf-8">
  <!---- >
  <base href="https://polygit.org/components/">
  <!---- >
  Toggle below/above as backup when server is down
  <!---->
  <base href="https://polygit2.appspot.com/components/">
  <!---->
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-fab/paper-fab.html" rel="import">
  <link href="iron-icons/iron-icons.html" rel="import">
</head>
<body>

<dom-module id="x-element">

<template>
  <style>
    paper-fab {
      margin: 15px;
    }
  </style>
  <paper-fab icon="add" elevation="5"></paper-fab>
  <paper-fab icon="add" elevation="4"></paper-fab>
  <paper-fab icon="add" elevation="3"></paper-fab>
  <paper-fab icon="add" elevation="2"></paper-fab>
  <paper-fab icon="add" elevation="1"></paper-fab>

</template>

<script>
  (function(){
    Polymer({
      is: "x-element",
    });
  })();
</script>

</dom-module>

<x-element></x-element>

</body>

在我看来元素有问题。在 documentation 中,听起来好像可以按您想要的方式使用。

The z-depth of this element, from 0-5. Setting to 0 will remove the shadow, and each increasing number greater than 0 will be "deeper" than the last

但是elevation 属性是只读的,所以设置没有效果。

paper-fab 实现了 paper-button-behavior。正如@Maria 提到的 elevation 仅 returns 结果海拔,它是只读的,无法设置。

您可以尝试添加属性,例如 raised (?)、focused (?)、disabled (0)、active (4)、pressed (4), receivedFocusFromKeyboard (3) 应该修改高度但似乎所有支持(如果有的话)。

I just found this issue report which confirms @Maria's answer.

因此,作为补丁,I am adding the following CSS code (jsBin) to add a shadow on hover to simulate the material design elevation spec here

Button Elevation. Raised buttons have a default elevation of 2dp. On desktop, raised buttons can gain this elevation on hover.

paper-fab:hover {
  box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.3);
}
http://jsbin.com/hitororuja/edit?html,输出
<!doctype html>
<head>
  <meta charset="utf-8">
  <!---- >
  <base href="https://polygit.org/components/">
  <!---- >
  Toggle below/above as backup when server is down
  <!---->
  <base href="https://polygit2.appspot.com/components/">
  <!---->
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-fab/paper-fab.html" rel="import">
  <link href="iron-icons/iron-icons.html" rel="import">
</head>
<body>

<dom-module id="x-element">

<template>
  <style>
    paper-fab:hover {
      box-shadow: 0 4px 10px 0 rgba(0, 0, 0, 0.3);
    }
  </style>
  <paper-fab icon="send"></paper-fab>

</template>

<script>
  (function(){
    Polymer({
      is: "x-element",
    });
  })();
</script>

</dom-module>

<x-element></x-element>

</body>