Vue 이동단 드래그 교환 위치 구현
<template>
<div class="imageUploaderPage">
<ul ref='imgList' class="imgList">
<li ref='imgItem' class="imgCoverItem" v-for='(item, index) in filesResults' :key='index' @click="deleteImage(index)"
:data-index='index'
@touchstart="touchstart($event, item, index)"
@touchmove="touchmove($event)"
@touchend="touchend($event)" >
<img :id="'avarimgs' + index" :src="item">
</li>
<li class="imgCoverItem upLoadImageWrapper">
<input ref='upLoadImageFile' id='upLoadImage' type='file' multiple="multiple" accept="image/*" @change="change" />
</li>
</ul>
<p> , , 4 </p>
<div class="btnConfimList" v-show="DeleteImageMask">
<div class="btnConfimListMask" @click='setDelete(false)'></div>
<transition name="transTop">
<div class="btnConfimListContent">
<ul>
<li class="borderT" > ?</li>
<li class="borderT" @click='setDelete(true)' style="color: var(--mRed);"> </li>
</ul>
<p class="cancelDeleteImage" @click='setDelete(false)'> </p>
</div>
</transition>
</div>
</div>
</template>
<script>
export default {
data () {
return {
files: [],
fileItem: {},
filesResults: [],
DeleteImageMask: false,
// isShow:false,
startX: 0, //
startY: 0,
moveX: 0, //
moveY: 0,
endX: 0,
endY: 0, //
disX: 0, //
disY: 0,
slideEffect: [], //
target: null,
startIndex: null,
zindex: 1,
leftW: 0,
targetW: 0,
clientW: 0,
targetX: 0,
targetY: 0,
allItems: [],
targetIndex: null
}
},
// computed: {
// toRightW () { return (this.leftW + this.targetW) * (this.startIndex + 1) - this.startX },
// toLeftW () { return this.startX - (this.leftW + this.targetW) * this.startIndex },
// toTopH () { return this.startY - parseInt(this.startIndex / 4) * (this.topH + this.targetW) },
// toBottomH () { return (this.topH + this.targetW) - this.startY + (this.leftW + this.targetW) * (parseInt(this.startIndex / 4)) }
// },
mounted () {
this.$nextTick(() => {
this.absoluteItems()
})
},
watch: {
slideEffect (newV) {
return newV
}
},
methods: {
change (e) {
var fileItem = e.target.files
let me = this
for (let i = e.target.files.length - 1; i >= 0; i--) {
var reader = new FileReader()
var file = e.target.files[i]
reader.onloadstart = function (e) {
// console.log(' ....')
}
reader.onprogress = function (e) {
// console.log(' ....')
}
reader.onabort = function (e) {
// console.log(' ....')
}
reader.onerror = function (e) {
// console.log(' ....')
}
reader.onload = function (e) {
if (me.filesResults.indexOf(e.target.result) >= 0) {
me.$toast(' ')
return
}
if (me.files.length >= 7) {
me.$toast(' 4 ')
return
}
me.files.unshift(fileItem)
me.filesResults.unshift(e.target.result)
}
reader.readAsDataURL(file)
}
},
absoluteItems () {
for (let i = 0; i < 8; i++) {
this.allItems = []
}
},
deleteImage (index) {
this.curIndex = index
this.DeleteImageMask = true
},
setDelete (data) {
this.DeleteImageMask = false
this.curIndex = null
data && this.curIndex >= 0 && this.files.splice(this.curIndex, 1) && this.filesResults.splice(this.curIndex, 1)
},
touchstart (e, item, index) {
this.startIndex = index
this.targetIndex = index
this.target = e.target.nodeName.toLowerCase() === 'li' ? e.target : e.target.parentNode
!this.leftW && (this.leftW = this.target.parentNode.querySelectorAll('li')[0].getBoundingClientRect().left)
!this.topH && (this.topH = this.target.parentNode.querySelectorAll('li')[0].getBoundingClientRect().top)
!this.targetW && (this.targetW = this.target.offsetWidth)
!this.clientW && (this.clientW = this.leftW + this.targetW)
this.zindex++
this.target.style.zIndex = this.zindex
this.startX = e.touches[0].clientX
this.startY = e.touches[0].clientY
},
touchmove (ev) {
ev = ev || window.event
ev.preventDefault()
if (ev.touches.length === 1) {
this.moveX = ev.touches[0].clientX
this.moveY = ev.touches[0].clientY
this.disX = this.moveX - this.startX
this.disY = this.moveY - this.startY
//
this.disY <= 0 && (this.disY = 0)
this.disY >= (this.$refs.imgList.offsetHeight - this.clientW) && (this.disY = this.$refs.imgList.offsetHeight - this.clientW)
this.target.style.transform = 'translate3d(' + this.disX + 'px,' + this.disY + 'px, 0)'
this.target.getBoundingClientRect().left <= 0 && (this.target.style.transform = 'translate3d(' + (-this.clientW * this.startIndex) + 'px,' + this.disY + 'px, 0)')
this.target.getBoundingClientRect().right >= this.$refs.imgList.offsetWidth && (this.target.style.transform = 'translate3d(' + this.clientW * (3 - this.startIndex) + 'px,' + this.disY + 'px, 0)')
for (let i = 0; i < this.filesResults.length; i++) {
// && this.moveY > this.$refs.imgItem[i].getBoundingClientRect().top && this.moveY < this.$refs.imgItem[i].getBoundingClientRect().top + this.targetW
if (this.moveX >= this.$refs.imgItem[i].getBoundingClientRect().left && this.moveX < this.$refs.imgItem[i].getBoundingClientRect().left + this.targetW && (i !== this.startIndex)) {
if (i > this.targetIndex && this.moveX >= this.$refs.imgItem[i].getBoundingClientRect().left && this.moveX < this.$refs.imgItem[i].getBoundingClientRect().left + this.targetW) {
if (this.$refs.imgItem[i].style.transform) {
if (this.$refs.imgItem[i].style.transform === 'translate3d(0px, 0px, 0px)') {
this.$refs.imgItem[i].style.transform = 'translate3d(' + (-this.clientW) + 'px, 0, 0)'
this.targetIndex = i
} else {
this.$refs.imgItem[i].style.transform = 'translate3d(0px, 0px, 0px)'
this.targetIndex = i - 1
}
} else {
this.$refs.imgItem[i].style.transform = 'translate3d(' + (-this.clientW) + 'px, 0, 0)'
this.targetIndex = i
}
} else if (i < this.targetIndex && this.moveX >= this.$refs.imgItem[i].getBoundingClientRect().left && this.moveX < this.$refs.imgItem[i].getBoundingClientRect().left + this.targetW) {
if (this.$refs.imgItem[i].style.transform) {
if (this.$refs.imgItem[i].style.transform === 'translate3d(0px, 0px, 0px)') {
this.$refs.imgItem[i].style.transform = 'translate3d(' + (this.clientW) + 'px, 0, 0)'
this.targetIndex = i
} else {
this.$refs.imgItem[i].style.transform = 'translate3d(0px, 0px, 0px)'
this.targetIndex = i + 1
}
} else {
this.$refs.imgItem[i].style.transform = 'translate3d(' + (this.clientW) + 'px, 0, 0)'
this.targetIndex = i
}
} else {
this.targetIndex > this.startIndex && (this.targetIndex = i - 1)
this.targetIndex < this.startIndex && (this.targetIndex = i + 1)
}
}
}
}
},
touchend (e) {
this.target.style.transform = 'translate3d(' + (this.targetIndex - this.startIndex) * (this.leftW + this.targetW) + 'px,' + this.targetY + 'px, 0)'
let start = this.filesResults.splice(this.startIndex, 1)[0]
this.filesResults.splice(this.targetIndex, 0, start)
for (let i = 0; i < this.filesResults.length; i++) {
this.$refs.imgItem[i].style.transform = 'none'
}
}
}
}
</script>
<style lang="less">
.imageUploaderPage{
background: #f0f0f3;
color: #a8a8a8;
overflow: hidden;
p{
text-align: center;
color: #a7a7a7;
height: 4.07vw;
line-height: 4.07vw;
font-size: var(--mText);
margin-bottom: var(--nText);
}
.imgList{
padding: 2.78vw 0;
font-size: 0;
position: relative;
.imgCoverItem{
position: relative;
width: 23.25vw;
height: 23.25vw;
border-radius: 1.11vw;
display: inline-block;
vertical-align: top;
overflow: hidden;
margin-left: 1.4vw;
margin-bottom: 1.4vw;
}
.upLoadImageWrapper{
position: relative;
background: #e0e0e0;
#upLoadImage{
position: absolute;
outline: none;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
}
}
}
</style>
이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fastapi websocket 및 vue 3(Composition API)1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.