<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery-3.5.1.min.js"></script>
<style>
*{
margin: 0px;
padding: 0px;
}
@keyframes donghua{
from
{
transform: scale(1);
opacity: 1;
}
to
{
transform: scale(0.5);
opacity: 0;
}
}
.split
{
animation: donghua 1s forwards;
}
#app
{
width: 750px;
height: 500px;
border: 1px solid #000000;
position: absolute;
left: calc((100% - 750px)/2);
top:calc((100vh - 500px)/2);
position: absolute;
}
#app>div
{
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
#app>.btn
{
position: absolute;
right: 10px;
bottom: 10px;
z-index: 2;
}
#app>.btn>li
{
width: 20px;
height: 20px;
background: #000000;
border: 1px solid #FFFFFF;
border-radius: 10px;
float: left;
opacity: 0.5;
list-style: none;
margin: 0 5px;
box-sizing: border-box;
}
#app>.btn>li:hover
{
background: #FFFFFF;
border: 1px solid #000000;
}
#app p
{
position: absolute;
background: #000000;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
$(function(){
const image = ["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg"]
let num = image.length;
const side = 50
const row_conunt = 500/50
const column_count = 750/50
const app = $('#app')
const ul = $('<ul class="btn"></ul>')
for(i = 0;i < num;i++)
{
$('<div></div>').css({
background: 'url(' + image[i] + ')',
'background-size':'750px 500px',
}).appendTo(app)
$('<li></li>').appendTo(ul)
}
ul.appendTo(app)
$('#app li').click(function(){
$('#app>p').remove()
const index = $(this).index();
if(index !== num)
{
$('#app div').eq(index).fadeIn() .siblings('div').fadeOut()
let startx = 0
let starty = 0
let endx = row_conunt - 1
let endy = column_count - 1
let x = 0
let y = 0
for(i= 0; i<row_conunt * column_count;i++)
{
const p = $('<p></p>').css({
width: side + 'px',
height: side + 'px',
background: 'url(' + image[num] + ')',
'background-position': (y * side * -1) + 'px ' + (x * side * -1) + 'px',
top: (side * x) + 'px',
left : (side * y) + 'px'
})
p.appendTo(app)
setTimeout(function(){
p.addClass('split')
},50 * i)
if(x === startx && y < endy)
{
y++
}else if(y === endy && x < endx)
{
x++
}else if(x === endx && y > starty)
{
y--
}else if(y === starty && x > startx)
{
x--
}
if(y === starty && x === startx + 1)
{
startx++
starty++
endx--
endy--
}
}
num = index
}
})
})
</script>
</body>
</html>