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

uni-app中实现元素拖动

uni-app中实现元素拖动

1、代码示例
<template><movable-area class="music-layout"><movable-view class="img-layout" :x="x" :y="y" direction="all"><img :src="musicDetail.bgUrl" :class="[ isPlay ? 'rotate-img' : '']" @click="onImgClick"><view class="small-circle"></view></movable-view></movable-area>
</template><script>
export default {name: "music-icon",props: {musicDetail: {type: Object,default: {}}},data() {return {innerAudioContext: {},x: 300,y: 500,isPlay: true,}},watch: {musicDetail: {handler(newVal, oldVal) {if (newVal.music) {this.handlePlay();}},immediate: true}},methods:{handlePlay() {this.innerAudioContext = uni.createInnerAudioContext();this.innerAudioContext.src = this.musicDetail.music;this.innerAudioContext.startTime = 0;this.innerAudioContext.play();this.innerAudioContext.loop = true; // 循环播放},onImgClick() {this.isPlay = !this.isPlay;if (this.isPlay) {this.innerAudioContext.play();} else {this.innerAudioContext.pause();}}}
}
</script><style scoped lang="scss">.music-layout {height: 100vh;width: 750rpx;top: 0;position: fixed;pointer-events: none; //鼠标事件可以渗透
}.img-layout {position: relative;width: 100rpx;height: 100rpx;border-radius: 50%;overflow: hidden;pointer-events: auto; //恢复鼠标事件img {width: 100%;height: 100%;border-radius: 50%;}.small-circle{position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);width: 20rpx;height: 20rpx;background-color: white;border-radius: 50%;}
}.rotate-img {width: 80rpx;height: 80rpx;border-radius: 50%;transform-origin: center center;animation: rotate 5s infinite linear;
}@keyframes rotate {from {transform: rotate(0deg);}to {transform: rotate(360deg);}
}
</style>

利用的是uni-app中的movable-area和movable-view两个组件配合实现

2、效果图展示

在这里插入图片描述

http://www.lryc.cn/news/275875.html

相关文章:

  • Java系列-Class.forName和ClassLoader.loadClass的区别
  • 找不到模块 “path“ 或其相对应的类型声明
  • Linux第17步_安装SSH服务
  • C语言—数据类型
  • 静态网页设计——多彩贵州(HTML+CSS+JavaScript)(dw、sublime Text、webstorm、HBuilder X)
  • unity PDFRender Curved UI3.3
  • 基于深度学习的停车位关键点检测系统(代码+原理)
  • C#,入门教程(09)——运算符的基础知识
  • 企业出海数据合规:GDPR中的个人数据与非个人数据之区分
  • 如何在Ubuntu搭建Emlog博客站点并发布至公网可随时远程访问管理界面——“cpolar内网穿透”
  • 【金猿CIO展】是石科技CIO侯建业:算力产业赋能,促进数字经济建设
  • TypeScript 类
  • Oracle分区表
  • 【leetcode】力扣算法之旋转图像【难度中等】
  • 【Java集合类篇】HashMap的数据结构是怎样的?
  • Spring 应用合并之路(一):摸石头过河 | 京东云技术团队
  • Android13配置selinux让system应用可读sys,proc,SN号
  • 防勒索病毒攻击的关键措施
  • 代表团坐车 - 华为OD统一考试
  • 运用Jmeter进行登录测试
  • Docker学习与应用(四)-容器数据卷
  • CentOS 7.6下HTTP隧道代理的安全性考虑
  • Mockito+junit5搞定单元测试
  • PostgreSQL获取当天、昨天、本月、上个月、本年、去年的数据
  • XCTF:stage1[WriteUP]
  • STM32CubeMX教程13 ADC - 单通道转换
  • 矩阵的乘法
  • python爬取招聘网站数据
  • 灌区信息化方案(什么是现代化灌区,如何一步到位)
  • jmeter自动录制脚本功能