微信小程序实现弹幕效果
来源:互联网 发布:光的双缝干涉实验 知乎 编辑:程序博客网 时间:2024/05/18 16:54
微信小程序实现弹幕效果
折腾了一周的微信小程序,一直在寻找弹幕效果,但是由于微信小程序的MVVM架构,很多HTML代码都无法运行,只有自己折腾一个出来。
效果:
主要原理是使用的CSS3的动画效果。
wxml代码:
<!--index.wxml--><view class="doommview"> <block wx:for="{{doommData}}" wx:key="id"> <text wx:if="{{item.display}}" class="aon" style="animation: first {{item.time}}s linear forwards;top:{{item.top}}%;color:{{item.color}};"> {{item.text}} </text> </block></view><view class="button"> <button bindtap="bindbt">弹一个小苹果</button></view>
wxss:
/**index.wxss**/.button{ position: absolute; bottom: 0; width: 100%;}.aon{position: absolute;white-space:nowrap;/* 防止向下换行*/}.doommview{ z-index: 3; height: 80%; width: 100%; position: absolute;}/**定义从右边向左边的移动的动画**/@keyframes first{ from{left: 100%; } to{left: -100%;}}
js:
//index.jsvar page = undefined;Page({ onLoad: function () { page = this; }, bindbt:function(){ doommList.push(new Doomm("你是我的小苹果",Math.ceil(Math.random()*100),Math.ceil(Math.random()*10),getRandomColor())); this.setData({ doommData : doommList }) }, data: { doommData:[] }})var doommList=[];var i=0;//用做唯一的wx:keyclass Doomm{ constructor(text,top,time,color){ this.text = text+i; this.top = top; this.time = time; this.color = color; this.display = true; let that = this; this.id = i++; setTimeout(function(){ doommList.splice(doommList.indexOf(that),1);//动画完成,从列表中移除这项 page.setData({ doommData : doommList }) },this.time*1000)//定时器动画完成后执行。 }}function getRandomColor() { let rgb = [] for (let i = 0; i < 3; ++i) { let color = Math.floor(Math.random() * 256).toString(16) color = color.length == 1 ? '0' + color : color rgb.push(color) } return '#' + rgb.join('')}
这样就可以实现一个弹幕效果,程序还有很多问题,还请各位看官见谅并指正。
项目地址:https://github.com/wjq1028/doomm
0 0
- 微信小程序实现弹幕效果
- Android弹幕效果实现
- 弹幕效果实现
- Jquery实现弹幕效果
- Android弹幕效果实现
- jquery实现弹幕效果
- Android---弹幕效果实现
- jQuery实现弹幕效果
- JS--实现弹幕效果
- jQuery实现弹幕效果
- Android实现弹幕效果
- GoEasy实现弹幕效果
- 简单实现弹幕效果
- Android:简易弹幕效果实现
- Unity3D实现弹幕的效果
- Android 简易弹幕效果实现
- RecyclerView实现的弹幕效果
- 使用DanmakuFlameMaster实现弹幕效果
- org.springframework.beans.factory.BeanDefinitionStoreException异常处理
- 【jzoj5094】【GDSOI2017第四轮模拟day3】【鸽子】【计算几何】
- MFC打印相关代码
- 电商总结
- Fisher–Yates shuffle 算法 Go 语言实现
- 微信小程序实现弹幕效果
- Unity之DOTweenPath轨迹移动
- jaxb的优点和用法
- HDU 1037 Keep on Truckin'
- 个人对python装饰器的理解
- 应用程序调试(四)————自制系统调用、编写进程查看器
- Java集合综述
- 客户端获取url传参对象的值
- 解决Ubuntu14.04下Sublime Text 3无法输入中文