2011-06-23 48 views
0

所以這可能是超級簡單的,但我試圖不對我的網頁上的第一個div使用makeshort函數。我怎樣才能不把東西應用到:第一項?

任何想法我做錯了什麼?如果不是優雅讓我知道 - 我是新手:)

function makeShort(){ 
    if (jQuery(this).not(':first')) { 
    jQuery(this).css('z-index','1').find('.bottom-bg .excerpt').animate({"height":75},200); 
    jQuery('.entry').removeClass('active').animate({opacity:1},200); 
    } 
} 
+2

'Query'?錯字? – Dogbert

+1

從哪裏調用makeShort? – Chandu

+1

「這個」來自哪裏?和你的CSS行應該使用jQuery,而不是查詢開始;) – Trey

回答

2

.mycollection是你的選擇

$('.mycollection:gt(0)') 

編輯

$(this).filter(':gt(0)') 

這會給你的所有項目在索引大於0的集合中(第一項)。所以,如果$(this)是3項的集合,$(this).filter(':gt(0)')會給你的第一個,在這個人爲的例子是最後2

參考畢竟項目:

0

巴斯編輯你添加的評論,你試圖過濾錯誤的地方。而不是在函數本身中進行篩選,只將hoverIntent應用於您想要的元素。

$("div").not(":first").hoverIntent(... 

然後makeShort就是:

function makeShort(){ 
    jQuery(this).css('z-index','1').find('.bottom-bg .excerpt').animate({"height":75},200); 
    jQuery('.entry').removeClass('active').animate({opacity:1},200); 
} 

這不適hoverIntent到第一div,所以你不必擔心它的功能。

EDIT(基於下面的評論):

function makeShort(){ 
     if(this!=jQuery("div:first")[0]){ 
     jQuery(this).css('z-index','1').find('.bottom-bg .excerpt').animate({"height":75},200); 
     jQuery('.entry').removeClass('active').animate({opacity:1},200); 
     } 
    } 
+0

感謝Kingjiv,但我確實希望hoverIntent中的其他一些事情發生在第一個div上,而不是makShort()函數。 – Sean

+0

@肖恩啊好吧,檢查我的編輯,我認爲這將起作用。可能想將'jQuery(「div:first」)[0]'保存到一個變量中,所以你不必每次選擇它。 –

+0

非常感謝!工作很好。爲什麼即使你說:首先是[0]是必要的? – Sean

相關問題