uni-app中實(shí)現(xiàn)元素拖動(dòng)效果
uni-app中實(shí)現(xiàn)元素拖動(dòng)
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; // 循環(huán)播放 }, 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; //鼠標(biāo)事件可以滲透 } .img-layout { position: relative; width: 100rpx; height: 100rpx; border-radius: 50%; overflow: hidden; pointer-events: auto; //恢復(fù)鼠標(biāo)事件 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兩個(gè)組件配合實(shí)現(xiàn)
2、效果圖展示
到此這篇關(guān)于uni-app中實(shí)現(xiàn)元素拖動(dòng)的文章就介紹到這了,更多相關(guān)uni-app元素拖動(dòng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
BootstrapValidator不觸發(fā)校驗(yàn)的實(shí)現(xiàn)代碼
BootstrapValidator是基于bootstrap3的jquery表單驗(yàn)證插件,是最適合bootstrap框架的表單驗(yàn)證插件,本文給大家介紹BootstrapValidator不觸發(fā)校驗(yàn)的實(shí)現(xiàn)代碼,感興趣的朋友一起看看吧2016-09-09Layui實(shí)現(xiàn)主窗口和Iframe層參數(shù)傳遞
今天小編就為大家分享一篇Layui實(shí)現(xiàn)主窗口和Iframe層參數(shù)傳遞,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11僅img元素創(chuàng)建后不添加到文檔中會(huì)執(zhí)行onload事件的解決方法
僅img元素創(chuàng)建后不添加到文檔中會(huì)執(zhí)行onload事件的解決方法,需要的朋友可以參考下。2011-07-07javascript 日期時(shí)間 轉(zhuǎn)換的方法
javascript 日期時(shí)間 轉(zhuǎn)換的方法,需要的朋友可以參考一下2013-02-02JS代碼實(shí)現(xiàn)根據(jù)時(shí)間變換頁面背景效果
這篇文章主要介紹了JS代碼實(shí)現(xiàn)根據(jù)時(shí)間變換頁面背景效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友一起看下吧2016-06-06