我有一個.pre和.next按鈕的卡魯塞爾。點擊.pre會將li移至li:最後移至li:首先以及其他方式。prependTo添加2個列表項而不是1
這工作得很好,如果只有一個卡魯塞爾,當我添加2個不同ID的卡魯塞爾點擊.pre添加2個李的前面,而不是1.爲什麼?
<div class="carrousel" id="featuredAppartments">
<a href="" class="move pre">Previous</a> <a href="" class="move next ">Next</a>
<div class="list">
<ul>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonLowered">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonRented">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonNew">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonNew">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonNew">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonNew">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
<li><a href=""><div class="imgWrap"><img src="assets/img/thumb2.png" alt=""><i class="ico ribbonNew">Featured</i></div> <p><strong>Amsterdam</strong> Grachtengordel <br> € 2500,00</p></a></li>
</ul>
</div>
<script>
$(document).ready(function() {
var t = $('#featuredAppartments ul');
$('.next').click(function(event) {event.preventDefault();t.find('li:first').appendTo(t);});
$('.pre').click(function(event) {event.preventDefault();t.find('li:last').prependTo(t);});
});
</script>
</div>
UPDATE:
我改劇本到這一點,但在第二輪播還是增加了2裏的,而不是僅僅1
<script>
$(document).ready(function() {
var t = $('#featuredAppartments ul');
$('#featuredAppartments .next').click(function(event) {event.preventDefault();t.find('li:first').appendTo(t);});
$('#featuredAppartments .pre').click(function(event) {event.preventDefault();t.find('li:last').prependTo(t);});
});
</script>
這是否重要?由於任何點擊任何.pre是好的,因爲它選擇了var t,這是一個特定的選擇器:t.find('li:first')。appendTo(t) – kevinius
好吧,我明白了......但爲什麼第二個旋轉木馬加2項而不是1? – kevinius