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

网站登陆模板全球速卖通是正规平台吗

网站登陆模板,全球速卖通是正规平台吗,网站建设及网页设计教案,天津做网站哪家好微信小程序红包雨功能实现:从组件封装到页面调用的完整实践 先看示例截图: 一、背景与技术选型 在微信小程序营销活动中,红包雨是一种极具吸引力的互动形式。实现红包雨效果主要有 Canvas 和图片两种方案: (1&…

微信小程序红包雨功能实现:从组件封装到页面调用的完整实践

先看示例截图:
红包雨示例截图

一、背景与技术选型
在微信小程序营销活动中,红包雨是一种极具吸引力的互动形式。实现红包雨效果主要有 Canvas 和图片两种方案:

(1)Canvas 方案:性能优异,资源占用小,但视觉表现依赖绘图 API
(2)图片方案:视觉效果真实,可灵活设计红包样式,但资源加载与内存占用较高

本文将采用图片方案实现红包雨组件,通过组件化设计提升代码复用性,并分享性能优化经验,帮助开发者在真实感与性能间找到平衡点。
二、组件设计与实现
2.1 组件结构设计
首先创建组件文件夹components/img-rain,目录结构如下:

components/
└─ img-rain/├── index.js         // 逻辑层├── index.wxml       // 视图层├── index.wxss       // 样式层├── index.json       // 配置文件└── images/             // 红包图片资源├── img1.png├── img2.png└── img3.png

2.2 组件核心代码实现
以下是图片红包雨组件的完整实现:

Component({properties: {petalCount: {type: Number,value: 60},speed: {type: Number,value: 2},wind: {type: Number,value: 0.3},images: {type: Array,value: ['/images/5.png','/images/100.png','/images/500.png','/images/1000.png']}},data: {petals: []},lifetimes: {attached() {this.createPetals();this.startAnimation();},detached() {this.stopAnimation();}},methods: {createPetals() {const {petalCount,images} = this.properties;const {windowWidth,windowHeight} = wx.getWindowInfo();const petals = [];for (let i = 0; i < petalCount; i++) {const size = 40 + Math.random() * 20;const left = Math.random() * (windowWidth - size);const top = -size - Math.random() * windowHeight;petals.push({id: `petal-${i}`,image: images[Math.floor(Math.random() * images.length)],x: left,y: top,size,speed: 5 + Math.random() * this.properties.speed,windEffect: (Math.random() - 0.5) * this.properties.wind});}this.setData({petals});},// 开始动画startAnimation() {const {windowHeight} = wx.getWindowInfo();this.animationInterval = setInterval(() => {this.setData({petals: this.data.petals.map(petal => {// 更新位置和旋转petal.y += petal.speed;petal.x += petal.windEffect;// 如果花瓣超出屏幕,重置到顶部if (petal.y > windowHeight + petal.size || petal.x < -petal.size || petal.x > wx.getWindowInfo().windowWidth + petal.size) {petal.y = -petal.size - Math.random() * windowHeight;petal.x = Math.random() * (wx.getWindowInfo().windowWidth - petal.size);}return petal;})});}, 30); // 约30ms一帧},// 停止动画stopAnimation() {if (this.animationInterval) {clearInterval(this.animationInterval);}},}
});

2.3 视图层实现

<view class="rain-container"><image wx:for="{{petals}}" wx:key="id" src="{{item.image}}" style="position: fixed;left: {{item.x}}px;top: {{item.y}}px;width: {{item.size}}px;height: {{item.size+20}}px;pointer-events: none;z-index: -1;"></image>
</view>

2.4 样式层实现

.rain-container {position: fixed;top: 0;left: 0;width: 100%;height: 100%;pointer-events: none;z-index: 9998;overflow: hidden;
}

三、页面调用与集成
3.1 页面配置
在需要调用的界面的json文件处引入组件

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

3.2 页面布局

<img-rain petalCount="10" speed="0" wind="0."></img-rain>

四、总结与拓展
本文通过组件化设计实现了微信小程序中基于图片的红包雨效果,兼顾了视觉真实感与代码复用性。实际项目中,可根据活动预算和性能要求选择合适的实现方案:

(1)对性能要求高、视觉要求低的场景推荐使用 Canvas 方案
(2)对视觉效果要求高、预算充足的场景推荐使用图片方案

编写不易,谢谢点赞+收藏+关注,后续更新更多示例呦~


文章转载自:

http://jcSzBPcg.qhmgq.cn
http://e6ubCpfU.qhmgq.cn
http://ipMlP2ax.qhmgq.cn
http://sIovBvt3.qhmgq.cn
http://kH686txl.qhmgq.cn
http://t7oJDS7w.qhmgq.cn
http://gnKrsm28.qhmgq.cn
http://dF8fbFKS.qhmgq.cn
http://l7uKjwzH.qhmgq.cn
http://NcyKuzPb.qhmgq.cn
http://rbcJr4nq.qhmgq.cn
http://dkanrKDw.qhmgq.cn
http://wATkagvT.qhmgq.cn
http://mPE8yQGg.qhmgq.cn
http://Tl9P0o17.qhmgq.cn
http://HXE9MkAf.qhmgq.cn
http://p6jwf6d7.qhmgq.cn
http://TNQ01bws.qhmgq.cn
http://B54TlksL.qhmgq.cn
http://h9b2FPAN.qhmgq.cn
http://Pqqgk6ls.qhmgq.cn
http://Z5gdq9Wv.qhmgq.cn
http://lUzulhyk.qhmgq.cn
http://j1mp3CkP.qhmgq.cn
http://ebJg1gr2.qhmgq.cn
http://TsLhD4kj.qhmgq.cn
http://Zig2G1kC.qhmgq.cn
http://d6kDovvj.qhmgq.cn
http://HiiEzjic.qhmgq.cn
http://6cM8Uu2n.qhmgq.cn
http://www.dtcms.com/wzjs/744097.html

相关文章:

  • 纯文本网站连接怎么做网站推广怎么样
  • 网站后台 添加用户企业营销型网站特点
  • 网站建设情况总结中国新闻社待遇
  • 剑三代售网站怎么做php钓鱼网站怎么做视频教程
  • 做家电维修网站能接到单吗wordpress付费知识
  • 西山区城市建设局网站最好看免费观看高清大全大理寺少
  • 潮州营销型网站建设推广百度公司做网站服务
  • 中国制造网官方网站国际站世安建设集团有限公司网站
  • 营销网站的关键字郑州东区网站优化公司推荐
  • 公司网站建设多少费用哪儿济南兴田德润联系电话竞价网站做招商加盟可以不备案吗
  • 如何设计公司网站wordpress page 分页
  • 企业3合1网站建设公司甘肃公司网站建设哪家好
  • 网站产品页面浙江省建设监理管理协会网站
  • 南昌网站建设品牌引流推广
  • 做爰免费视频网站昆明企业网站开发
  • 有些人做网站不用钱的,对吗?专门做推广的网站
  • 深圳做网站公司有那些wordpress连接数据库文件
  • 洛阳建设网站公司有前景的网站建设
  • 网站权重有什么用微网站一键通话
  • 东莞 网站设计化妆品营销型网站模板下载
  • 无锡做网站f7wl建设网站需要哪些硬件
  • j建设银行查数据的网站网站粘度
  • 建设部2018年工作要点网站网站方案怎么写
  • 科学数据分析网站html5淘宝网站做推广收费吗
  • 张家港做网站玉树商城网站建设
  • 龙岗网站设计案例建设银行网站表单清理
  • 云南省和城乡建设厅网站网站开发读什么专业
  • 网站建设数据库是什么意思网站主题模板制作
  • phpcms 恢复网站做视频网站用哪个软件好
  • 滨江网站开发优书网书单推荐