Polymer 1.0 - paper-ripple goes all over the screen instead fit in the element

一曲冷凌霜 提交于 2019-12-05 06:37:55

NOTE: If you are experiencing this behaviour, or behaviour similar to it, in the latest version of paper-ripple, it is likely that the problem that this answer addresses is not the problem you are experiencing (see update below).

paper-ripple has the following CSS (only relevant lines shown):

:host {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

If the paper-ripple's parent element does not have position: relative set, this will result in the ripple filling the first position: relative parent that it finds, which may not be its immediate parent, or the whole document, whichever comes first.

To fix this, make sure that the element you are using paper-ripple in has position: relative in its CSS.

UPDATE (15 June 2015): paper-ripple 1.0.1 was released on 11 June 2015, which includes the PR fixing this problem, making the fixes recommended in this answer obsolete. Simply update bower.json to bind to PolymerElements/paper-ripple#^1.0.1.


This problem is caused by a current issue with paper-ripple. What is happening is that the paper-ripple elements are targeting the my-list element instead of their parent paper-icon-item element.

There are currently two ways to fix this:

  1. In the meantime, create a custom element that has a paper-ripple element in its shady/shadow DOM, and size it to fit your element.

    For example:

<dom-module id="ripple-wrapper">
  <style is="custom-style">
    :host {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    }
  </style>
  <template>
    <paper-ripple></paper-ripple>
  </template>
</dom-module>
<script>
  Polymer({ is: 'ripple-wrapper' });
</script>
  1. I have submitted a pull request to the repository that contains a fix for this problem. Currently, however, it hasn't been merged yet. For now, you can tell bower to install the patched copy of paper-ripple by setting the version of paper-ripple in your bower.json file to vsimonian/paper-ripple#containment-fix.

    If you do this, I highly recommend that you keep tabs on the issue and pull request so that you may revert the temporary changes in bower.json when they are no longer needed.

zerodevx

It is probably with noting that - as a potential gotcha - it is important to set the ripple container element to position: relative;

I was wondering why ripples fill the root container despite already defining my box sizes.

http://jsbin.com/zijumuhege/edit?html,output

The opening <style>tag is missing in my-list.html.

It seems as if triggering the ripple effect on a <paper-ripple> element triggers it on all other <paper-ripple> elements inside that custom element as well. Creating a custom element for the items or moving everything outside of a custom element seem to solve the problem for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!