這篇文章主要介紹“Vue怎么制作波紋按鈕”,在日常操作中,相信很多人在Vue怎么制作波紋按鈕問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Vue怎么制作波紋按鈕”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、西鄉(xiāng)塘ssl等。為近1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的西鄉(xiāng)塘網(wǎng)站制作公司
先說一下用法:
<zk-button class="btn btn-default">默認(rèn)按鈕</zk-button> <zk-button class="btn btn-default btn-round">默認(rèn)按鈕</zk-button> <zk-button class="btn btn-default btn-round" :speed="4" :opacity="0.6">定義速度和初始的波浪透明度</zk-button>
原理:
這里用的是canvas + requestAnimationFrame(兼容性可以網(wǎng)上找一下解決方法) 繪制的波紋,有些用的是css transform + setTimeout做的,我感覺不太好。
模板(template):
<template> <button class="zk-btn"> <canvas class="zk-ripple" @click="ripple"></canvas> <slot></slot> </button> </template>
點擊代碼如下(我已經(jīng)加入詳細(xì)的注釋)
ripple(event) { // 清除上次沒有執(zhí)行的動畫 if (this.timer) { window.cancelAnimationFrame(this.timer); } this.el = event.target; // 執(zhí)行初始化 if (!this.initialized) { this.initialized = true; this.init(this.el); } this.radius = 0; // 點擊坐標(biāo)原點 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和獲取用戶點擊的位置坐標(biāo),并開始繪制。
循環(huán)繪制
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; } }
到此,關(guān)于“Vue怎么制作波紋按鈕”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
文章題目:Vue怎么制作波紋按鈕
分享鏈接:http://sd-ha.com/article0/ggepoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、搜索引擎優(yōu)化、關(guān)鍵詞優(yōu)化、小程序開發(fā)、Google、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)