微信小程序———点击屏幕涟漪效果

本文介绍了一个使用JavaScript实现的触摸反馈效果。当用户在屏幕上点击时,会在点击位置生成一个扩大的透明圆圈作为视觉反馈。该效果利用了CSS动画和触摸事件进行定位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

js中

  containerTap: function (res) {
    console.log(res.touches[0]);
    var x = res.touches[0].pageX;
    var y = res.touches[0].pageY + 85;
    this.setData({
      rippleStyle: ''
    });
    this.setData({
      rippleStyle: 'top:' + y + 'px;left:' + x + 'px;-webkit-animation: ripple 0.4s linear;animation:ripple 0.4s linear;'
    });
  }

wxml中

<view>

<view class="ripple" style="{{rippleStyle}}"></view>

<view class="container" bindtouchstart="containerTap"></view>

</view>

wxss中

.container{
    width:100%;
    height:500px;
}
.ripple {
    background-color: rgba(50%,70%, 60%, 0.6);
    border-radius: 100%;
    height:10px;
    width:10px;
    margin-top: -90px;
    position: absolute;
    -webkit-transform: scale(0);
}
@-webkit-keyframes ripple {
    100% {
    -webkit-transform: scale(12);
    transform: scale(12);
    background-color: transparent;
    }
}

点击屏幕后会出现这个 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值