我有滑塊div內的一些項目,我想動畫左邊-299px每次點擊跳過類的事件被觸發,並且動畫回到其正常位置,如果它到達與。連續滑動div
請問我該如何做到這一點?
我試過了,但它只動畫-299px並停止。
我已經寫了一些HTML,CSS和jQuery例如:
CSS
<style>
.items{
width:299px;
height:80px;
float:left;
color:white;
}
.slider{
min-width:1495px;
height:80px;
}
.container{
width:299px;
height:80px;
}
.one{
background-color:red;
}
.two{
background-color:yellow;
}
.three{
background-color:red;
}
HTML
<a href='#' class='skip'>Skip</a>
<div class='container'>
<div class='slider'>
<div class='items one'>Item 1</div>
<div class='items two'>Item 2</div>
<div class='items three'>Item 3</div>
</div>
</div>
JQUERY
//skiping check em outerHTML
$(document).on('click','.skip',function(e){
e.preventDefault();
$('.slider').animate({marginLeft:"-299px"},"fast");
//stop default behaviour
return false;
});
正是我想要的......太感謝你了 –
@詹姆斯Oduro我看到有一個嘗試編輯這個,所以我會跟進。你會想在事件處理程序之外做選擇器,所以它只發生一次。這是爲了表現。沒有理由每次都查找元素。 – Taplar