<span class="img bg1" data-index="0">span>
<span class="img bg2" data-index="1">span>
<span class="img bg3" data-index="2">span>
<span class="img bg4" data-index="3">span>
<span class="img bg5" data-index="4">span>
<span class="img bg6" data-index="5">span>
const imgs = document.querySelectorAll('.img')
const main = document.querySelector('#main')
const zw = document.querySelector('.zw')
const isMobile = navigator.userAgent.match(/Mobile/)
const move = (el, x, y) => {
el.setAttribute('style', `pointer-events:none;position:absolute;left:${x}px;top:${y}px`)
document.addEventListener(isMobile ? 'touchstart' : 'mousedown', e => {
isMobile && (e = e.touches[0])
index = e.target.dataset.index
py.left = e.pageX - imgs[index].offsetLeft
py.top = e.pageY - imgs[index].offsetTop
zw.style.display = 'block'
main.insertBefore(zw, imgs[index])
move(imgs[index], e.pageX - py.left, e.pageY - py.top)
document.addEventListener(isMobile ? 'touchmove' : 'mousemove', e => {
isMobile && (e = e.touches[0])
move(imgs[index], e.pageX - py.left, e.pageY - py.top)
document.addEventListener(isMobile ? 'touchend' : 'mouseup', e => {
imgs[index].setAttribute('style', '')
main.insertBefore(imgs[index], zw)
v.addEventListener(isMobile ? 'touchmove' : 'mouseenter', e => {
isMobile && (e = e.touches[0])
const list = [...main.children]
const imgIndex = list.findIndex(el => v == el)
const zwIndex = list.findIndex(el => zw == el)
if (zwIndex < imgIndex) {
justify-content: space-evenly;
background: no-repeat center center;
background-image: url('https://cdn.pixabay.com/photo/2020/02/05/22/01/bush-4822500__480.jpg');
background-image: url('https://cdn.pixabay.com/photo/2022/01/24/13/51/temple-6963458__480.jpg');
background-image: url('https://cdn.pixabay.com/photo/2020/12/02/01/06/chipmunk-5795916__480.jpg');
background-image: url('https://img0.baidu.com/it/u=3488728512,3798628168&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500');
background-image: url('https://img1.baidu.com/it/u=2837573517,2587904370&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750');
background-image: url('https://img0.baidu.com/it/u=3647457944,660791411&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=750');