中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

什么是網(wǎng)站獨立訪問者數(shù)量seo如何優(yōu)化關(guān)鍵詞上首頁

什么是網(wǎng)站獨立訪問者數(shù)量,seo如何優(yōu)化關(guān)鍵詞上首頁,php網(wǎng)站開發(fā)實例教程源代碼,公司網(wǎng)站建設(shè)哪個最好微信小程序使用畫布實現(xiàn)飄落泡泡功能:從組件封裝到頁面調(diào)用的完整實踐 先看示例截圖: 一、背景與技術(shù)選型 在微信小程序中實現(xiàn)類似于飄落的泡泡或者櫻花飄落的功能,一般主要有 Canvas 和圖片兩種方案: (1&#xff…

微信小程序使用畫布實現(xiàn)飄落泡泡功能:從組件封裝到頁面調(diào)用的完整實踐

先看示例截圖:
示例截圖

一、背景與技術(shù)選型
在微信小程序中實現(xiàn)類似于飄落的泡泡或者櫻花飄落的功能,一般主要有 Canvas 和圖片兩種方案:

(1)Canvas 方案:性能優(yōu)異,資源占用小,但視覺表現(xiàn)依賴?yán)L圖 API
(2)圖片方案:視覺效果真實,但資源加載與內(nèi)存占用較高

本文將采用Canvas 方案實現(xiàn)飄落的泡泡組件,通過組件化設(shè)計提升代碼復(fù)用性,并分享性能優(yōu)化經(jīng)驗,幫助開發(fā)者在真實感與性能間找到平衡點。
二、組件設(shè)計與實現(xiàn)
2.1 組件結(jié)構(gòu)設(shè)計
首先創(chuàng)建組件文件夾components/down-rain,目錄結(jié)構(gòu)如下:

components/
└─ down-rain/├── index.js         // 邏輯層├── index.wxml       // 視圖層├── index.wxss       // 樣式層├── index.json       // 配置文件

2.2 組件核心代碼實現(xiàn)
以下是組件的完整實現(xiàn):

Component({properties: {// 數(shù)量petalCount: { type: Number, value: 60 },//  大小petalSize: { type: Array, value: [3, 8] },// 下落速度speed: { type: Number, value: 2 },// 風(fēng)力影響wind: { type: Number, value: 0.3 },},data: {canvasWidth: 0,canvasHeight: 0,ctx: null,animationTimer: null,petals: []},lifetimes: {attached() {this.initCanvas();},detached() {this.stopAnimation();}},methods: {// 初始化Canvasasync initCanvas() {const query = this.createSelectorQuery();query.select('.canvas').boundingClientRect();const { windowWidth, windowHeight } = wx.getSystemInfoSync();const canvas = wx.createCanvasContext('downCanvas', this);this.setData({canvasWidth: windowWidth,canvasHeight: windowHeight,ctx: canvas,petals: this.createPetals()});this.startAnimation();},// 創(chuàng)建花瓣數(shù)組 - 修改:從隨機位置開始下落createPetals() {const { petalCount, petalSize } = this.properties;const { canvasWidth, canvasHeight } = this.data;const vanishLine = canvasHeight * 2 / 3; // 消失線位置return Array(petalCount).fill().map(() => {// 隨機生成初始位置,y可以在畫布上方const y = Math.random() * canvasHeight * 1.5 - canvasHeight * 0.5;return {x: Math.random() * canvasWidth,y,size: petalSize[0] + Math.random() * (petalSize[1] - petalSize[0]),speed: 0.5 + Math.random() * this.properties.speed,angle: Math.random() * Math.PI * 2,wind: (Math.random() - 0.5) * this.properties.wind,alpha: 0.5 + Math.random() * 0.5,startY: y, // 記錄起始Y坐標(biāo)用于計算消失visible: y < vanishLine // 初始可見性判斷};});},// 開始動畫startAnimation() {this.data.animationTimer = setInterval(() => {this.updatePetals();this.drawPetals();}, 30);},// 停止動畫stopAnimation() {if (this.data.animationTimer) {clearInterval(this.data.animationTimer);}},// 更新位置updatePetals() {const { canvasWidth, canvasHeight, petals } = this.data;const vanishLine = canvasHeight * 2 / 3; this.setData({petals: petals.map(petal => {petal.y += petal.speed;petal.x += Math.sin(petal.angle) * petal.wind;petal.angle += 0.02;// 計算與消失線的距離比例const distanceRatio = Math.max(0, (petal.y - vanishLine) / (canvasHeight - vanishLine));// 超過消失線后逐漸消失if (distanceRatio > 0) {petal.alpha = Math.max(0, petal.alpha * (1 - distanceRatio));petal.visible = petal.alpha > 0;} else {petal.visible = true;petal.alpha = 0.5 + Math.random() * 0.5; // 重置透明度}// 完全消失后重置位置if (!petal.visible || petal.y > canvasHeight) {return {x: Math.random() * canvasWidth,y: -10, // 從頂部重新開始size: petal.size, // 保持原有大小speed: 0.5 + Math.random() * this.properties.speed,angle: Math.random() * Math.PI * 2,wind: petal.wind, // 保持原有風(fēng)力影響alpha: 0.5 + Math.random() * 0.5,startY: -10,visible: true};}return petal;})});},// 繪制drawPetals() {const { ctx, petals } = this.data;ctx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight);petals.forEach(petal => {if (petal.visible) {ctx.beginPath();ctx.arc(petal.x, petal.y, petal.size, 0, Math.PI * 2);ctx.fillStyle = `rgba(255, 192, 203, ${petal.alpha})`;ctx.fill();}});ctx.draw(false);},}
});

2.3 視圖層實現(xiàn)

<canvas class="canvas" canvas-id="downCanvas"></canvas>

2.4 樣式層實現(xiàn)

.canvas {position: fixed;top: 0;left: 0;width: 100%;height: 100%;pointer-events: none;z-index: 999;
}

三、頁面調(diào)用與集成
3.1 頁面配置
在需要調(diào)用的界面的json文件處引入組件

{"usingComponents": {"down-rain": "/components/down-rain/index"},"navigationStyle": "custom"
}

3.2 頁面布局

<down-rain petalCount="50" speed="5"></down-rain>

四、總結(jié)與拓展
本文通過組件化設(shè)計實現(xiàn)了微信小程序中基于Canvas 的飄落泡泡的效果。實際項目中,可根據(jù)活動預(yù)算和性能要求選擇合適的實現(xiàn)方案:

(1)對性能要求高、視覺要求低的場景推薦使用 Canvas 方案
(2)對視覺效果要求高、預(yù)算充足的場景推薦使用圖片方案

編寫不易,謝謝點贊+收藏+關(guān)注,后續(xù)更新更多示例呦~

http://www.risenshineclean.com/news/4245.html

相關(guān)文章:

  • 門戶網(wǎng)站開發(fā)需求分析網(wǎng)絡(luò)營銷未來有哪些發(fā)展趨勢
  • wordpress怎么靜態(tài)頁面東莞搜索優(yōu)化十年樂云seo
  • wordpress最新的編輯器南寧網(wǎng)站優(yōu)化
  • 可以轉(zhuǎn)app的網(wǎng)站怎么做資深seo顧問
  • 網(wǎng)站建設(shè)全套教程含前端和后端關(guān)鍵詞排名客服
  • ppt網(wǎng)站鏈接怎么做seo排名關(guān)鍵詞搜索結(jié)果
  • 成都市做網(wǎng)站的公司百度推廣app怎么收費
  • 網(wǎng)站后綴百度影響力排名順序
  • 怎么創(chuàng)建私人網(wǎng)站微信推廣多少錢一次
  • 國外推廣網(wǎng)站國內(nèi)營銷推廣渠道
  • 做蛋白go分析網(wǎng)站高端企業(yè)網(wǎng)站定制公司
  • 美橙表業(yè)手表網(wǎng)站2023年5月份病毒感染情況
  • 有域名 有主機 怎么建設(shè)網(wǎng)站獨立站seo外鏈平臺
  • 東莞seo建站優(yōu)化方法如何制作一個網(wǎng)頁鏈接
  • 江西做企業(yè)網(wǎng)站的公司無錫網(wǎng)絡(luò)推廣外包
  • 中山網(wǎng)站優(yōu)化關(guān)鍵詞排名優(yōu)化公司哪家強
  • dw做旅游網(wǎng)站模板下載網(wǎng)頁搜索排名提升
  • 網(wǎng)站備案 假通信地址seo深圳培訓(xùn)班
  • 新疆建設(shè)兵團125團網(wǎng)站什么是網(wǎng)站
  • 網(wǎng)站如何做原創(chuàng)文章什么是關(guān)鍵詞舉例說明
  • 煙臺開發(fā)區(qū)網(wǎng)站制作公司快速優(yōu)化網(wǎng)站排名的方法
  • 東莞網(wǎng)站seo推廣優(yōu)化金蝶進銷存免費版
  • 郴州網(wǎng)站建設(shè)公司官網(wǎng)steam交易鏈接怎么改
  • 做網(wǎng)站首頁有什么網(wǎng)絡(luò)推廣網(wǎng)站的方法
  • 網(wǎng)站的發(fā)布與推廣怎么寫seo優(yōu)化包括
  • 營業(yè)執(zhí)照申請網(wǎng)站互聯(lián)網(wǎng)營銷的特點
  • 創(chuàng)意簡約啤酒徽章logo設(shè)計頁面優(yōu)化的方法有哪些
  • 市場推廣seo職位描述百度seo怎么收費
  • 網(wǎng)站建設(shè)需具備的條件南寧網(wǎng)站公司
  • 福州網(wǎng)站建設(shè)網(wǎng)絡(luò)公司排名seo網(wǎng)站推廣如何做