2013-07-30 23 views
0

我有一個非常標準的滑塊組件滑塊UL。在滑塊div中查找可見元素

我想將活動類添加到視口中只有可見元素。我嘗試了谷歌搜索,但所有在vail。有沒有人能夠對此有所瞭解?

enter image description here

以下是滑動代碼:

// get all lists that slider was initialised on 
$lists = $(this.container).find('> ul'); 

// get current left position of list 
currentPos = $lists.position().left; 

// new left position of list is width of a page times target page number 
newLeftPos = currentPos - (530 * (newPageNum-1)); 

回答

1
if($("li").is(":visible")){ 
    $(this).addClass('active'); 
} 
+0

我不認爲這會工作,因爲李的總是可見的? – RuntimeException

+0

視口中的可見元素http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport – Sbml

+0

謝謝,你提供的最後一個鏈接確實工作。謝謝。 – RuntimeException