当前位置: 首页 > news >正文

uniapp实现 uview1 u-button的水波纹效果

说明:

由于uview2已经移除水波纹效果,这边又觉得那个效果好看,所以开发这个功能(原谅我不会录动图)

效果:

水波纹

具体代码:

<view class="ripple-container" @touchstart="handleTouchStart" @touchend="handleTouchEnd"><view class="btn"><text>登录</text></view><!-- 水波纹元素 --><view v-if="showRipple" class="ripple-effect" :style="{left: rippleX + 'px',top: rippleY + 'px',width: rippleSize + 'px',height: rippleSize + 'px'}"></view>
</view><script>export default {data() {return {// 水波纹showRipple: false,rippleX: 0,rippleY: 0,rippleSize: 0 // 根据按钮大小动态计算};},methods: {handleTouchStart(event) {// 获取按钮布局信息const query = uni.createSelectorQuery().in(this);query.select('.ripple-container').boundingClientRect(rect => {if (!rect) return;// 计算点击位置(相对于按钮)const touch = event.touches[0];this.rippleX = touch.clientX - rect.left;this.rippleY = touch.clientY - rect.top;// 计算波纹大小(取按钮宽高中的最大值)this.rippleSize = Math.max(rect.width, rect.height);// 触发动画this.showRipple = true;}).exec();},handleTouchEnd() {// 动画结束后重置状态setTimeout(() => {this.showRipple = false;}, 600); // 与动画时间保持一致}}}
</script><style lang="scss" scoped>.btn {border: none;border-radius: 10rpx;color: #fff;background-color: #3f39ff;padding: 10rpx 20rpx;}// 水波纹样式.ripple-container {position: relative;display: inline-block;overflow: hidden;@keyframes ripple {from {transform: translate(-50%, -50%) scale(0);opacity: 1;}to {transform: translate(-50%, -50%) scale(2);opacity: 0;}}.ripple-effect {position: absolute;z-index: 0;background: rgba(0, 0, 0, 0.15);border-radius: 100%;background-clip: padding-box;transform: translate(-50%, -50%);pointer-events: none;user-select: none;transform: scale(0);opacity: 1;transform-origin: center;animation: ripple 0.6s ease-out;}}
</style>

http://www.mrgr.cn/news/94313.html

相关文章:

  • 使用memmove优化插入排序
  • 新闻网页信息抽取
  • JVM 垃圾回收器的选择
  • 广播机制(Broadcasting)
  • 项目组织管理类型-职能式组织和矩阵式组织的区别
  • HOT100——二叉树篇Leetcode236. 二叉树的最近公共祖先
  • windows 下用docker 部署nginx
  • 项目组织管理类型-矩阵式组织和组合式组织的区别
  • RSA混合加密RSA混合加密
  • MySQL 8 设置允许远程连接(Windows环境)
  • 使用 Excel 实现绩效看板的自动化
  • 微信小程序:实现多功能表格效果,例如滚动效果、宽度自定义、多选、行内编辑等功能
  • 如何在Ubuntu上构建编译LLVM和ISPC,以及Ubuntu上ISPC的使用方法
  • 【不动产登记全解析】范围、内容与不予登记的情形
  • Android 11.0 监听某个app启动或者退出功能实现
  • 【Pandas】pandas Series last_valid_index
  • 什么是OF
  • 【20】单片机编程核心技巧:类型强制与中间变量解决运算溢出
  • java枚举解析
  • 2024年第十五届蓝桥杯软件C/C++大学A组——五子棋对弈