简体   繁体   English

悬停第一格会影响所有其他第一格

[英]Hover 1st DIV affect all other 1st DIVS

I'm asking a basic question here, for some reason I can't get it to work. 我在这里提出一个基本问题,由于某种原因我无法使其正常工作。 Any help will be appreciated. 任何帮助将不胜感激。

Here's what I'm trying to do using either CSS or JQUERY http://css-tricks.com/examples/RowColumnHighlighting/example-two.php 这是我尝试使用CSS或JQUERY进行的操作http://css-tricks.com/examples/RowColumnHighlighting/example-two.php

Basicaly I have: 基本上我有:

<div class="block1">
  <div></div>
  <div></div>
  <div></div>
</div>
<div class="block2">
  <div></div>
  <div></div>
  <div></div>
</div>
<div class="block3">
  <div></div>
  <div></div>
  <div></div>
</div>
<div class="block4">
  <div></div>
  <div></div>
  <div></div>
</div>

I want to be able to hover the first div in any of the blocks and all the other first div will be highlighted as well. 我希望能够将第一个div悬停在任何块中,其他所有第一个div也将突出显示。 Same thing for the second or third div of each block. 每个块的第二个或第三个div同样。 I hope I'm explaining this correctly. 我希望我能正确解释。

If there's any other related post I don't mind. 如果还有其他相关的帖子,我不在乎。

Thank you very much. 非常感谢你。

You could try something like 您可以尝试类似

div.block1:hover>div *{
    color:red;
}

div.block1 div:hover>div *{
    color:red;
}

here we go. 开始了。 working jsfiddle example: http://jsfiddle.net/fLkRQ/ 有效的jsfiddle示例: http//jsfiddle.net/fLkRQ/

$("div[class^='block']").children('div').hover(function(e){

    var index = $(this).index();
    $("div[class ^='block']").children('div').each(function(){
    if ($(this).index() == index){
        $(this).addClass('highligted')
    } else {
     $(this).removeClass('highligted');
    }
})                        
})

you should use jQuery index() method. 您应该使用jQuery index()方法。 Read more here - http://api.jquery.com/index/ Hope this helps 在此处了解更多信息-http: //api.jquery.com/index/希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM