简体   繁体   English

纸纹不亮

[英]Paper ripple does not fire

I have this code as a custom element: 我将此代码作为自定义元素:

<link rel="import" href="../paper-ripple/paper-ripple.html">

<polymer-element name="menu-item">

<template>
    <style>
        :host {
            box-sizing: border-box;
            position: absolute;
            font-size: 16px;
            width:100%;
        }


.center{
   text-align: center;
}
    </style>

        <div class="item">
            <div class="content center" fit>
                <content select="*"></content>
            </div>
            <paper-ripple fit></paper-ripple>
        </div>


</template>

<script>

    Polymer({

    });

</script>

It is instantiated as follows: <menu-item><a href="{{url('#/')}}">Home</a></menu-item> 实例化如下: <menu-item><a href="{{url('#/')}}">Home</a></menu-item>

Problem is, either the ripple fires and the link does not. 问题是,要么是纹波触发,要么是链接没有触发。 Or the link fires but the ripple does not. 否则,链路会触发,但涟漪不会触发。

How should I be doing this? 我应该怎么做?

Thanks, g3 谢谢,g3

I was able to get it to work by changing your code to create the element to have the anchor tags around the element, like so: 我可以通过更改代码来创建元素以使元素周围具有锚标记,从而使其正常工作,如下所示:

<a href="{{url('#/')}}"><menu-item>site</menu-item></a>

removing select="*" from your content element, and giving your :host style some height. 从您的content元素中删除select="*" ,并为您的:host样式设置一些高度。 I set mine to height: 32px; 我将我的height: 32px;设置为height: 32px;

I think the basic problem is that the way you have it structured, the anchor tag and the paper-ripple are siblings, so there's no way for the click event to bubble up from the ripple to the anchor, or vice versa. 我认为基本问题是您的结构方式,锚标记和纸波纹是兄弟姐妹,因此单击事件无法从涟漪上升到锚,反之亦然。

One approach would be to have the anchor tag inside your element and use data binding, like so: 一种方法是在元素内放置锚标记并使用数据绑定,如下所示:

<div class="item">
  <a href="{{url}}">
    <div class="content center" fit>
      {{text}}
    </div>
    <paper-ripple fit></paper-ripple>
   </a>
 </div>

...

<menu-item url="{{url('#/')}}" text="Home"></menu-item>

Full demo here: 完整的演示在这里:

http://jsbin.com/bumiva/3/edit http://jsbin.com/bumiva/3/edit

Another approach would be to use your original structure and add a click listener on the outer <div> and follow the link manually, like this: 另一种方法是使用您的原始结构,并在外部<div>上添加一个点击侦听器,然后手动跟随链接,如下所示:

http://jsbin.com/wadiwu/2/edit http://jsbin.com/wadiwu/2/edit

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM