JavaScript-聚合物纸波纹
作者:互联网
我试图在按下按钮时更改元素的颜色.
我希望在按下按钮并更改颜色时在该元素中触发纸张波纹效果.
我应该怎么做?
目标元素:
<paper-toolbar class="abc">
<paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
<div flex class="indent title">Heading</div>
</paper-toolbar>
触发元素:
<paper-button class="def background-blue"></paper-button>
<paper-button class="def background-red"></paper-button>
Javascript:
$(".def").click(function(){
$(".abc").css("background-color", $(this).css("background-color"));
});
解决方法:
代替直接在纸张工具栏上直接操作样式,一种更多的元素方法是在纸张工具栏旁边添加一个paper-ripple元素,并在您的纸张按钮上调用mousedown / mouseup时手动调用downAction / upAction.
<paper-header-panel class="fit">
<paper-toolbar class="toolbar">
<paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
<div flex class="indent title">Heading</div>
<paper-ripple id="ripple" center></paper-ripple>
</paper-toolbar>
<div>
<paper-button class="def background-blue"raised on-mousedown="_onMousedown" on-mouseup="_onMouseup">Go blue</paper-button>
<paper-button class="def background-red" raised on-mousedown="_onMousedown" on-mouseup="_onMouseup">Go red</paper-button>
</div>
</paper-header-panel>
请注意,纸波纹的背景色是彩色.
_assignColor: function(e) {
var button = Polymer.dom(e).localTarget;
var ripple = this.$.ripple;
$(ripple).css("color", $(button).css("background-color"));
// or without jQuery
//var buttonStyle = getComputedStyle(button, null);
//ripple.style.color = buttonStyle.backgroundColor;
},
_onMousedown: function (e) {
this._assignColor(e);
this.$.ripple.downAction({x: e.x, y: e.y});
},
_onMouseup: function (e) {
this._assignColor(e);
this.$.ripple.upAction();
}
看看这个plunker.
标签:material-design,polymer,polymer-1-0,javascript,jquery 来源: https://codeday.me/bug/20191119/2038204.html