3
我有一個包含的元素被設置爲溢出隱藏UL溢出容器。我將如何去獲取可見的li?你會如何編寫一個jQuery函數來返回一個沒有溢出父類的元素數組?
我的標記:
<div class="dm-similar-photos-content-container">
<ul class="carousel" style="left: 0px;">
<li class="dm-image">
<img data-photoid="1" src="http://lorempixel.com/150/150/food/1">
</li>
<li class="dm-image">
<img data-photoid="2" src="http://lorempixel.com/150/150/food/2">
</li>
<li class="dm-image">
<img data-photoid="3" src="http://lorempixel.com/150/150/food/3">
</li>
<li class="dm-image">
<img data-photoid="4" src="http://lorempixel.com/150/150/food/4">
</li>
<li class="dm-image">
<img data-photoid="5" src="http://lorempixel.com/150/150/food/5">
</li>
<li class="dm-image">
<img data-photoid="6" src="http://lorempixel.com/150/150/food/6">
</li>
<li class="dm-image">
<img data-photoid="7" src="http://lorempixel.com/150/150/food/7">
</li>
<li class="dm-image">
<img data-photoid="8" src="http://lorempixel.com/150/150/food/8">
</li>
<li class="dm-image">
<img data-photoid="9" src="http://lorempixel.com/150/150/food/9">
</li>
<li class="dm-image">
<img data-photoid="10" src="http://lorempixel.com/150/150/food/10">
</li>
</ul>
</div>
<div>
<a class="left">
<- Left
</a>
<a class="right">
Right ->
</a>
</div>
我的風格:
.dm-similar-photos-content-container {
margin: 0 30px;
overflow: hidden;
width: 335px;
}
.carousel {
margin: 0;
padding: 0;
position: relative;
width: 9999px;
}
.dm-similar-photos-content-container .dm-image {
margin: 13px 27px 13px 0;
}
.dm-image {
float: left;
list-style: none outside none;
margin: 16px 16px 0 0;
position: relative;
}
.dm-image img {
border: 2px solid #7F8886;
}
最後是簡單的左,右JS:
jQuery('.left').on('click', function() {
jQuery(".carousel").animate({
left: "-=181"
});
});
jQuery('.right').on('click', function() {
jQuery(".carousel").animate({
left: "+=181"
});
});
你可以在這裏看到:http://jsfiddle.net/GGhUF/
我想你可以用'$(元素).offset()top'和'$(元素).offset()left',並將其與母公司的股利尺寸比較。不知何故。 –