Uniapp实现商城购买消息淡入淡出功能

2023-10-22 18:10

本文主要是介绍Uniapp实现商城购买消息淡入淡出功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果如下:

具体代码

先封装一个组件,名字FadeInOut.vue

<template><view><viewref="ani":animation="animationData"class="message":style="{ top: top + 'px', left: left + 'px' }"v-if="show"><view class="round bg-gradual-orange flex justify-start shadow" style="padding: 3px;"><view class="cu-avatar cu-a-sm round" :style="{ backgroundImage: `url(${info.img})` }"><!-- #ifdef APP-NVUE --><image :src="info.img" class="avatarimg"></image><!-- #endif --></view><view class="padding-lr-sm flex align-center"><text class="text-sm">{{ info.title }}</text></view></view></view></view>
</template><script>
// #ifdef APP-NVUE
const animation = uni.requireNativePlugin('animation');
// #endif
export default {name: 'Pengpai-FadeInOut',props: {//持续时间duration: {type: Number,default: 2600},//停留时间wait: {type: Number,default: 3000},//顶部距离pxtop: {type: Number,default: 350},//左边距离pxleft: {type: Number,default: 10},//动画半径radius: {type: Number,default: 30},//数据info: {type: [Array,Object],default: () => {return []}}},data() {return {animationData: {},animationNumber:{},show: true};},mounted(){this.donghua();},watch:{},methods: {donghua() {//进入// #ifndef APP-NVUEthis.animationData = uni.createAnimation({duration: this.duration / 2,timingFunction: 'ease'}).top(this.top - this.radius).opacity(0.9).step().export();// #endif// #ifdef APP-NVUEif (!this.$refs['ani']) return;animation.transition(this.$refs['ani'].ref,{styles: {transform: `translateY(-${this.radius/2}px)`,opacity: 1},duration: this.duration/2,timingFunction: 'linear',needLayout: false,delay: 0});// #endif//停留setTimeout(() => {//消失// #ifndef APP-NVUEthis.animationData = uni.createAnimation({duration: this.duration / 2,timingFunction: 'ease'}).top(this.top - this.radius * 2).opacity(0).step().export();// #endif// #ifdef APP-NVUEif (!this.$refs['ani']) return;animation.transition(this.$refs['ani'].ref,{styles: {transform: `translateY(-${this.radius}px)`,opacity: 0},duration: this.duration/2,timingFunction: 'linear',needLayout: false,delay: 0});// #endif}, this.wait);}}
};
</script><style scoped>
.message {position: fixed;z-index: 99999;opacity: 0;
}
.round {border-radius: 5000px;
}
.bg-gradual-orange {background-image: linear-gradient(45deg, #ff9700, #ed1c24);background-image: linear-gradient(to bottom right, #ff9700, #ed1c24);color: #ffffff;
}
.shadow {box-shadow: 4px 4px 5px rgba(217, 109, 26, 0.2);
}
.flex {display: flex;flex-direction: row;
}
.justify-start {justify-content: flex-start;
}
.cu-avatar {font-variant: small-caps;display: inline-flex;white-space: nowrap;background-size: cover;background-position: center;vertical-align: middle;margin: 0;padding: 0;text-align: center;justify-content: center;align-items: center;background-color: #ccc;color: #ffffff;position: relative;width: 30px;height: 30px;font-size: 1.5em;
}.avatarimg {width: 30px;height: 30px;border-radius: 50px;
}.cu-a-sm {width: 30px;height: 30px;font-size: 1em;
}
.padding-lr-sm {padding-left: 20upx;padding-right: 20upx;
}
.align-center {align-items: center;
}
.margin-left-xs {margin-left: 10upx;
}
.text-bold {font-weight: bold;
}
.margin-lr-sm {margin-left: 20upx;margin-right: 20upx;
}
.text-sm {font-size: 15px;color: #ffffff;
}
</style>

然后引入这个组件

<template><view><Pengpai-FadeInOut:duration="2000":wait="1000":top="150":left="10":radius="60":loop="true":info="item"v-for="(item, index) in list":key="index"></Pengpai-FadeInOut></view>
</template><script>import PengpaiFadeInOut from '../../components/Pengpai-FadeInOut/Pengpai-FadeInOut.vue'
export default {components:{PengpaiFadeInOut},data() {return {list: [],//演示数据demo_data: [{title: '踮起脚尖走向阳光 刚刚浏览本店',img: 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83er0aq5WuQhWxXcQoQbSnSPywUheQrot5biaFxV47nF2OB0aegkH12q2A6VkGUBDfUVqiaqgzVCJJicDg/132'},{title: '幸福的小女人  刚刚浏览本店',img: 'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIOeUhleCNwcOoTtk9Y1zwmpw76FsmAr1bYcKia2AVPiapbtl34jac7SQgjMaibKDJCqjYaHwvmUh3IQ/132'},{title: '快乐天使  刚刚浏览本店',img: 'https://wx.qlogo.cn/mmopen/vi_32/OaXz0rjMsrHkZlfxeEqRhhUCKyaXyVSbCQZWFUeZQuUetKhbQRZiclqNQhFfv3yiclOzTl1FgZdjDpwAFG5gDhBg/132'},{title: '握不住的沙  刚刚浏览本店',img: 'https://wx.qlogo.cn/mmopen/vi_32/bVfMeCPxSQsfBRc1XFHiaAiaZvvdrXC9hMTWAHoqDZKk7HD2By7km1dc55eSEibibKwDaW3ZQ2Zcbccr4KzwILVquQ/132'},{title: '顺其自然  刚刚浏览本店',img: 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJghoO6zuibOUG6AMubJJIUicbbWjyOyljFr4QVZecvRqEhHfkIribPfEyfxiaKY5MpiaAeVjvokLLATDw/132'}]};},methods: {add() {//随机获取演示数据let randomItem = this.demo_data[Math.floor(Math.random() * this.demo_data.length)];//追加一条数据this.list = this.list.concat(randomItem);}},onLoad() {setInterval(()=>{this.add()},3000)}
};
</script><style></style>

OK,完事

这篇关于Uniapp实现商城购买消息淡入淡出功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/262899

相关文章

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

PostgreSQL中MVCC 机制的实现

《PostgreSQL中MVCC机制的实现》本文主要介绍了PostgreSQL中MVCC机制的实现,通过多版本数据存储、快照隔离和事务ID管理实现高并发读写,具有一定的参考价值,感兴趣的可以了解一下... 目录一 MVCC 基本原理python1.1 MVCC 核心概念1.2 与传统锁机制对比二 Postg

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

C++中零拷贝的多种实现方式

《C++中零拷贝的多种实现方式》本文主要介绍了C++中零拷贝的实现示例,旨在在减少数据在内存中的不必要复制,从而提高程序性能、降低内存使用并减少CPU消耗,零拷贝技术通过多种方式实现,下面就来了解一下... 目录一、C++中零拷贝技术的核心概念二、std::string_view 简介三、std::stri

C++高效内存池实现减少动态分配开销的解决方案

《C++高效内存池实现减少动态分配开销的解决方案》C++动态内存分配存在系统调用开销、碎片化和锁竞争等性能问题,内存池通过预分配、分块管理和缓存复用解决这些问题,下面就来了解一下... 目录一、C++内存分配的性能挑战二、内存池技术的核心原理三、主流内存池实现:TCMalloc与Jemalloc1. TCM