开发者

How can I not apply something to the :first item?

So this is probably super simple but I am trying to not applyong the makeshort function to the first div on my page.

Any idea what I'm doing wrong? If it's not elegant let me know-I'm a newbie :)

function makeShort(){ 
  if  (jQuery(this).not(':first')) {
    jQuery(this).css('z-index','1').find('.bottom-bg .excerpt').animate({"height":75},200);
    jQuery('.entry').removeClass('act开发者_JAVA技巧ive').animate({opacity:1},200);
  }
}


.mycollection is your selector

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

EDIT

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

this will give you all the items in the collection whose index is greater than 0 (the first item). So if $(this) is a collection of 3 items, $(this).filter(':gt(0)') will give you all items after the first one, which in this contrived example would be the last 2.

References:

  • Working Fiddle Demo
  • :gt(index)
  • .filter()


Based on the comment you added, you are trying to filter in the wrong place. Rather than filtering in the function itself, only apply hoverIntent to the elements you want it on.

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

and then makeShort is just:

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

This will not apply hoverIntent to the first div so you don't need to worry about it in the function.

EDIT (based on comment below):

   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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜