<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/transform.css">
<script src="../js/jquery-3.5.1.min.js"></script>
<style>
.add-box,.remove-box{
background-color:#f1f1f1;
height: 200px;
overflow-y: auto;
overflow-x: hidden;
}
.add-span,.remove-span{
border:1px solid #aaa;
border-radius: 3px;
font-size: 0.7rem;
padding:0.2rem 0.4rem;
transition: 0.1s;
width: calc((100% / 4) - 0.6rem);
display:block;
float: left;
margin: 0.3rem;
background-color:white;
}
.add-span i,.remove-span i{
font-size: 0.7rem;
padding-right: 0.1rem;
padding-left: 0.2rem;
transition: 0.3s;
float: right;
}
.add-span i{
color: #007bff;
}
.remove-span i{
color: #dc3545;
}
.add-span:hover,.remove-span:hover{
background-color:#cce5ff;
border-color: #b8daff;
cursor: pointer;
}
.add-span:active{
background-color:#007bff;
border-color: #007bff;
cursor: pointer;
color: white;
}
.remove-span:active{
background-color:#dc3545;
border-color: #dc3545;
cursor: pointer;
color: white;
}
.add-span:active i,.remove-span:active i{
cursor: pointer;
color: white;
}
</style>
</head>
<body>
<div class="row" style="margin: 0;">
<div class="col-sm-12 col-md-6">
<div class="remove-box">
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="add-box">
<span index="2014" class="add-span">五險一金<i class="icon-icon_im_more iconfont"></i></span>
<span index="2015" class="add-span">週末雙休<i class="icon-icon_im_more iconfont"></i></span>
<span index="2016" class="add-span">包食宿<i class="icon-icon_im_more iconfont"></i></span>
<span index="2017" class="add-span">通訊補貼<i class="icon-icon_im_more iconfont"></i></span>
<span index="2018" class="add-span">年底雙薪<i class="icon-icon_im_more iconfont"></i></span>
<span index="2019" class="add-span">餐宿補貼<i class="icon-icon_im_more iconfont"></i></span>
<span index="2020" class="add-span">年底旅遊<i class="icon-icon_im_more iconfont"></i></span>
<span index="2021" class="add-span">年終分紅<i class="icon-icon_im_more iconfont"></i></span>
<span index="2022" class="add-span">加班補助<i class="icon-icon_im_more iconfont"></i></span>
<span index="2023" class="add-span">帶薪年假<i class="icon-icon_im_more iconfont"></i></span>
<span index="2024" class="add-span">股票期權<i class="icon-icon_im_more iconfont"></i></span>
<span index="2025" class="add-span">交通補貼<i class="icon-icon_im_more iconfont"></i></span>
<span index="2026" class="add-span">高溫補貼<i class="icon-icon_im_more iconfont"></i></span>
<span index="2027" class="add-span">彈性工作<i class="icon-icon_im_more iconfont"></i></span>
<span index="2028" class="add-span">採暖補貼<i class="icon-icon_im_more iconfont"></i></span>
<span index="2029" class="add-span">醫療保險<i class="icon-icon_im_more iconfont"></i></span>
<span index="2030" class="add-span">定期體檢<i class="icon-icon_im_more iconfont"></i></span>
<span index="2031" class="add-span">免費班車<i class="icon-icon_im_more iconfont"></i></span>
</div>
</div>
</div>
<script>
let addlist = [];
let sublist = [];
$("document").ready(function () {
for (var i = 0; i < $(".add-box .add-span").length; i++) {
addlist.push($(".add-box .add-span").eq(i).attr("index"));
}
})
var ul = document.querySelector('.add-box');
ul.addEventListener('click', function (e) {
addSpan(e.target)
});
function addSpan(data) {
var index = $(data).index();
var text = $(".add-box .add-span").eq(index).text();
var spanIndex = $(".add-box .add-span").eq(index).attr("index");
var html = `<span class="remove-span" οnclick="removeSpan(this)" index="` + spanIndex + `">` + text + `<i class="icon-icon_roundclose iconfont"></i></span>`;
$(".add-box .add-span").eq(index).remove();
$(".remove-box").prepend(html);
addlist.splice(addlist.indexOf(spanIndex), 1);
sublist.push(spanIndex);
console.log('addlist1', addlist);
console.log('sublist1', sublist);
}
function removeSpan(data) {
var index = $(data).index();
var text = $(".remove-box .remove-span").eq(index).text();
var spanIndex = $(".remove-box .remove-span").eq(index).attr("index");
var html = `<span class="add-span" οnclick="addSpan(this)" index="` + spanIndex + `">` + text + `<i class="icon-icon_im_more iconfont"></i></span>`;
$(".remove-box .remove-span").eq(index).remove();
$(".add-box").prepend(html);
addlist.push(spanIndex);
sublist.splice(sublist.indexOf(spanIndex), 1);
console.log('addlist2', addlist);
console.log('sublist2', sublist);
}
</script>
</body>
</html>