在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML5  HTML/ 如何將新插入的元素根據(jù)之前元素進(jìn)行排序

如何將新插入的元素根據(jù)之前元素進(jìn)行排序

效果:倒金字塔型效果
效果圖:
圖片描述

要求:
1.左邊選中的內(nèi)容放到右邊金字塔中(追加到右側(cè));
2.右邊的內(nèi)容不可重復(fù)
3.刪除后,新加入的元素要根據(jù)之前元素情況重新排序,不能打亂倒金字塔效果(如果上面比較短,新追加的比較長(zhǎng),新加的要放到短的上面)
圖片描述
刪除部分后,1,3為新加入的,要實(shí)現(xiàn)的效果順序?yàn)椋?,2,3,4,5

本來(lái)是想根據(jù)div的背景位置做比較,但最后沒(méi)能拿到,問(wèn)題3就一直沒(méi)解決掉,有沒(méi)有js厲害的朋友給幫忙解決一下,小妹在此先謝過(guò),抱拳!??!

說(shuō)明:每列的梯形是用背景圖做的,每個(gè)相差31px。
部分代碼:
<div class="FL selectedTag">

                        <h3 class="titles">選中標(biāo)簽</h3>
                        <ul>
                            <li class="tags relative" flag="0" style="background-position-y: -93px;"><div class="centerDiv" aval="dc_digital_apptype:2" title="APP偏好:微信">APP偏好:微信</div><span class="absolute close" style="right: 29px;">x</span></li><li class="tags relative" flag="1" style="background-position-y: -155px;"><div class="centerDiv" aval="dc_digital_databand:D" title="手機(jī)流量:1-5MB">手機(jī)流量:1-5MB</div><span class="absolute close" style="right: 41px;">x</span></li><li class="tags relative" flag="2" style="background-position-y: -155px;"><div class="centerDiv" aval="dc_digital_resident:livingORworking" title="常駐:居住和工作">常駐:居住和工作</div><span class="absolute close" style="right: 41px;">x</span></li><li class="tags relative" flag="3" style="background-position-y: -93px;"><div class="centerDiv" aval="dc_digital_sex:B" title="性別:女">性別:女</div><span class="absolute close" style="right: 29px;">x</span></li><li class="tags relative" style="background-position-y: -124px;"><div class="centerDiv" aval="dc_digital_hascar:A" title="是否車(chē)主:是">是否車(chē)主:是</div><span class="absolute close" style="right: 35px;">x</span></li><li class="comNum">
                                <div class="comNumCon ml_10 FL">當(dāng)前可操作人數(shù) <b>0人</b></div>
                                <button id="countPeople" class="FL t_c LH30 ml_10 medium_btn border_btn_blue borderRadius colorDefault" style="background-color: #6CA9FC">計(jì)算人數(shù)
                                </button>
                            </li>
                        </ul>
                    </div>
                    
                    

.selectedTag{

width: 300px;

}
.tags,.comNum{

margin-bottom: 2px;
width: 300px;
height: 30px;
color: #8f9eb2;
font-size: 12px;

}
.tags{

background: url("../images/tagBg.png") no-repeat;
background-position-x: 0px;

}
.comNumCon{

width: 180px;
margin-bottom: 2px;
height: 30px;
font-size: 12px;
color: #ffffff;
background: url("../images/tagBg.png") no-repeat -52px -301px;

}
.comNumCon b{

font-size: 14px;
font-weight: 900;

}

.tags:nth-last-child(2){

margin-bottom: -2px;

}

.close{

width: 16px;
height: 16px;
top:7px;
font-size: 12px;
font-weight: lighter;
background-color: #ffffff;
border-radius: 50px;
color: #bfcad6;
text-align: center;
line-height: 14px;
cursor: pointer;
/*background: url("../images/close20.png") no-repeat 0 0;*/

}
.tags div,.comNum div{

width: 180px;
text-align: center;
height: 100%;
line-height: 30px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

}

回答
編輯回答
病癮

不知道你的每個(gè)div的長(zhǎng)度是怎么計(jì)算的?是固定的不同的類型不同的長(zhǎng)度?還是看里面字符串的內(nèi)容?
不管是按照什么規(guī)則制定的長(zhǎng)度,我的理解是你把金字塔的div固定,變的只不過(guò)是里面的內(nèi)容,那么給每個(gè)內(nèi)容定義為一個(gè)對(duì)象,放到數(shù)組里,再排序,排序好了再放上去:

data = [{
   text: '性別啥哎哎',
   width: 10
}, {
   text: 'shifdsadsa哎',
   width: 12
}]
data.sort(function(a,b){
 return a.width - b.width
})

然后循環(huán)data,創(chuàng)建dom

2018年4月27日 14:46