Vue波纹按钮组件制作

?默认按钮
默认按钮
定义速度和初始的波浪透明度

原理:
这里用的是canvas + requestAnimationFrame(兼容性可以网上找一下解决方法) 绘制的波纹,有些用的是css transform + setTimeout做的,我感觉不太好。
模板(template):









点击代码如下(我已经加入详细的注释)


ripple(event) {
// 清除上次没有执行的动画
if (this.timer) {
window.cancelAnimationFrame(this.timer);
}
this.el = event.target;
// 执行初始化
if (!this.initialized) {
this.initialized = true;
this.init(this.el);
}
this.radius = 0;
// 点击坐标原点
this.origin.x = event.offsetX;
this.origin.y = event.offsetY;
this.context.clearRect(0, 0, this.el.width, this.el.height);
this.el.style.opacity = this.opacity;
this.draw();
},

这里主要初始化canvas和获取用户点击的位置坐标,并开始绘制。
循环绘制


draw() {
this.context.beginPath();
// 绘制波纹
this.context.arc(this.origin.x, this.origin.y, this.radius, 0, 2 * Math.PI, false);
this.context.fillStyle = this.color;
this.context.fill();
// 定义下次的绘制半径和透明度
this.radius += this.speed;
this.el.style.opacity -= this.speedOpacity;
// 通过判断半径小于元素宽度或者还有透明度,不断绘制圆形
if (this.radius < this.el.width || this.el.style.opacity > 0) {
this.timer = window.requestAnimationFrame(this.draw);
} else {
// 清除画布
this.context.clearRect(0, 0, this.el.width, this.el.height);
this.el.style.opacity = 0;
}
}

总结:
上面代码我没有复制完整,大家想看源码可以下载看一下
这是4月最后一天上班了,5.1要好好休息一下。


您可能感兴趣的文章:[url=http://www.biwenge.com/upload/2018062116/u4xjfxjccfc.htm]React为 Vue 引入容器组件和展示组件的教程详解[/url][url=http://www.biwenge.com/upload/2018062116/avuuwgcg5hw.htm]Vue表单类的父子组件数据传递示例[/url][url=http://www.biwenge.com/upload/2018062116/4nmvjzfiew0.htm]Vue SSR 组件加载问题[/url][url=http://www.biwenge.com/upload/2018062116/gfx0mf2xlwo.htm]vue中的模态对话框组件实现过程[/url][url=http://www.biwenge.com/upload/2018062116/izxtiivkrhq.htm]使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件(推荐)[/url][url=http://www.biwenge.com/upload/2018062116/503yu1tlsbt.htm]Vue实现PopupWindow组件详解[/url][url=http://www.biwenge.com/upload/2018062116/v0zldrh3lri.htm]vue弹窗组件使用方法[/url][url=http://www.biwenge.com/upload/2018062116/5itclj440th.htm]学习Vue组件实例[/url][url=http://www.biwenge.com/upload/2018062116/oh2hvj0e22d.htm]vue弹窗消息组件的使用方法[/url][url=http://www.biwenge.com/upload/2018062116/ub02pz5mg5b.htm]详解vue组件基础[/url]

-[url=https://blog.youkuaiyun.com/qq_42485486/article/details/80762283]Vue%E6%B3%A2%E7%BA%B9%E6%8C%89%E9%92%AE%E7%BB%84%E4%BB%B6%E5%88%B6%E4%BD%9C[/url]

[url=https://blog.youkuaiyun.com/qq_42485212/]测试足球平台出租环境调试app[/url]
[url=https://blog.youkuaiyun.com/qq_42485451/]js缓存足球平台出租加载到app[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值