我如何不能对:first项目应用某些内容?

问题描述

| 因此,这可能非常简单,但我尝试不将makeshort函数应用于页面的第一个div。 知道我在做什么错吗?如果不是很优雅,请告诉我-我是新手:)
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);
  }
}
    

解决方法

        
.mycollection
是您的选择器
$(\'.mycollection:gt(0)\')
编辑
$(this).filter(\':gt(0)\')
这将为您提供集合中索引大于0的所有项目(第一个项目)。因此,如果
$(this)
是3件物品的集合,则
$(this).filter(\':gt(0)\')
将为您提供第一个物品之后的所有物品,在这个人为的示例中,这将是最后一个2。 参考文献: 工作小提琴演示 :gt(索引) 。过滤()     ,        根据您添加的注释,您尝试在错误的位置进行过滤。除了对函数本身进行过滤之外,仅对要使用的元素应用ѭ6。
$(\"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);
}
这对第一个ѭ10not不会应用
hoverIntent
,因此您无需在函数中担心它。 编辑(基于下面的评论):
   function makeShort(){
      if(this!=jQuery(\"div:first\")[0]){ 
        jQuery(this).css(\'z-index\',200);
        jQuery(\'.entry\').removeClass(\'active\').animate({opacity:1},200);
      }
   }
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...