2015-10-16 54 views
1

我使用Rubaxa sortable來製作可以排序的列表項。現在我想更改被拖動列表的背景顏色。 現在我使用文檔中提供的ghost類,但只有文本背景是彩色的,但我希望整個列表以及編號都具有背景色。 任何人都可以知道如何添加自定義類到可排序的通過javascript,以便我可以實現相同。更改Rubaxa中可拖拽列表的背景顏色排序?

Sortable.create(simpleList, { 
 
    ghostClass: "ghost" 
 
    });
.ghost { 
 
    color: #fff; 
 
    background-color: #c00; 
 
} 
 
.container { 
 
    text-align: center; 
 
} 
 
ol { 
 
    display: inline-block; 
 
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="http://rubaxa.github.io/Sortable/Sortable.js"></script> 
 
<div class="container"> 
 
    <ol id="simpleList" class="list-group"> 
 
    <li>A Good Meal</li> 
 
    <li>A technical Improvement</li> 
 
    <li>Nonsense</li> 
 
    </ol> 
 
</div>

+0

如果我的理解是正確的給出.LIST組 – Snm

+1

100%寬度你想整個'ul'到有相同的顏色?或者就是那個被拖動的特定'li'?因爲,正如你可以看到特定的'li'在被拖動時丟失了它的編號。所以請澄清你的問題 –

+0

李不會鬆散其編號,如果列表是100%的寬度。只需檢查下面的片段 – Snm

回答

2

最後,我做到了。請檢查this。我在您的htmlcssJquery中做了一些更改。

HTML

<div class="container"> 
    <ol id="simpleList" class="list-group"> 
     <li><span class="index">1.</span>A Good Meal</li> 
     <li><span class="index">2.</span>A technical Improvement</li> 
     <li><span class="index">3.</span>Nonsense</li> 
    </ol> 
</div> 

CSS

.ghost { 
    color: #fff; 
    background-color: #c00; 
    position: relative; 
} 
.index { 
    display: inline-block; 
    height: 100%; 
    width: 10px; 
    margin-right: 10px; 
    background: inherit; 
    color: inherit; 
} 
.container { 
    text-align: center; 
} 
ol { 
    display: inline-block; 
    list-style:none; 
    text-align: left; 
} 

jQuery的

Sortable.create(simpleList, { 
    ghostClass: "ghost", 
    onEnd: function (/**Event*/ evt) { 
     $('.list-group li').each(function (index) { 
      var newIndex = index + 1 + '.'; 
      $(this).find('.index').html(newIndex); 
     }); 
    } 
}); 
+0

幹得好,男人! ;) –

+0

@TheDarkKnight哈哈哈。 tnx – Alex

+0

@ vikrantnegi007這就是你的答案嗎? – Alex

2

Sortable.create(simpleList, { 
 
    ghostClass: "ghost" 
 
    });
.ghost { 
 
    color: #fff; 
 
    background-color: #c00; 
 
} 
 
.container { 
 
    text-align: center; 
 
} 
 
ol { 
 
    display: inline-block; 
 
} 
 

 
.list-group{width:100%}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" /> 
 
<script src="http://rubaxa.github.io/Sortable/Sortable.js"></script> 
 
<div class="container"> 
 
    <ol id="simpleList" class="list-group"> 
 
    <li>A Good Meal</li> 
 
    <li>A technical Improvement</li> 
 
    <li>Nonsense</li> 
 
    </ol> 
 
</div>

+0

這不是他問的。他要求列表中的數字具有相同的背景顏色 –

+0

,如果列表中的數字具有相同的背景顏色,則表示不會顯示。 – Snm

+0

你的意思是「它不會被看見?」 –