button 点击的涟漪效果


button点击时 ,在5.0以上的系统还有涟漪的效果,在需要修改的Button中添加android:theme属性,引用新建的Style即可。


使用方式如下:

        <Button
            ...
            android:theme="@style/Button"
            />

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
    <style name="Button" parent="Theme.AppCompat">
        //点击颜色
        <item name="colorControlHighlight">@color/indigo_500</item>
        //背景颜色
        <item name="colorButtonNormal">@color/pink_200</item>
    </style>

或者另一种 设置 直接在button控件中设置 如下属性
android:background="?android:listChoiceBackgroundIndicator"



要给`el-button`加上涟漪动画效果,需要使用`waves`指令来实现。具体步骤如下: 1. 首先,需要在`<template>`标签中引入`waves.css`文件,该文件用于控制涟漪动画效果的样式,代码如下: ```html <template> <div> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/waves.css"> <el-button v-waves>点击我</el-button> </div> </template> ``` 2. 然后,在`<script>`标签中注册`waves`指令,代码如下: ```javascript export default { directives: { waves: { bind(el, binding) { el.addEventListener('mousedown', e => { const customOpts = Object.assign({}, binding.value) const opts = Object.assign({ ele: el, // 波纹作用元素 type: 'hit', // hit 点击位置扩散 center中心点扩展 color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色 }, customOpts) const target = opts.ele if (target) { target.style.position = 'relative' target.style.overflow = 'hidden' const rect = target.getBoundingClientRect() let ripple = target.querySelector('.waves-ripple') if (!ripple) { ripple = document.createElement('span') ripple.className = 'waves-ripple' ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px' target.appendChild(ripple) } else { ripple.className = 'waves-ripple' } switch (opts.type) { case 'center': ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px' ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px' break default: ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.documentElement.scrollTop) + 'px' ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.documentElement.scrollLeft) + 'px' } ripple.style.backgroundColor = opts.color ripple.className = 'waves-ripple z-active' return false } }, false) } } } } ``` 3. 最后,在`<el-button>`标签中添加`v-waves`指令即可,代码如下: ```html <template> <div> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/waves.css"> <el-button v-waves>点击我</el-button> </div> </template> <script> export default { directives: { waves: { bind(el, binding) { el.addEventListener('mousedown', e => { const customOpts = Object.assign({}, binding.value) const opts = Object.assign({ ele: el, // 波纹作用元素 type: 'hit', // hit 点击位置扩散 center中心点扩展 color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色 }, customOpts) const target = opts.ele if (target) { target.style.position = 'relative' target.style.overflow = 'hidden' const rect = target.getBoundingClientRect() let ripple = target.querySelector('.waves-ripple') if (!ripple) { ripple = document.createElement('span') ripple.className = 'waves-ripple' ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px' target.appendChild(ripple) } else { ripple.className = 'waves-ripple' } switch (opts.type) { case 'center': ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px' ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px' break default: ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.documentElement.scrollTop) + 'px' ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.documentElement.scrollLeft) + 'px' } ripple.style.backgroundColor = opts.color ripple.className = 'waves-ripple z-active' return false } }, false) } } } } </script> ``` 这样就可以给`el-button`添加涟漪动画效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值