2012-07-19 69 views
0

我有一個網格中的鏈接列表和一個垂直菜單,用於鏈接到一邊。我試圖鏈接這兩組,這樣當你將鼠標懸停在網格中的項目上時,菜單項也會突出顯示,反之亦然。下面是我到目前爲止有:將懸停狀態鏈接到兩個元素上

/* Grid */ 
<div class="pos-content count1"></div> 
<div class="pos-content count2"></div> 
<div class="pos-content count3"></div> 

/* Menu */ 
<ul> 
<li class="item177">Menu Link 1</li> 
<li class="item178">Menu Link 2</li> 
<li class="item179">Menu Link 3</li> 
</ul> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $('div.count1').click(function() { 
     $("#item177").trigger("mouseover"); 
    }); 
}); 
</script> 

相關:Count the number of elements with a specific class, then add an ID that numbers them

+0

和問題是? – PhD 2012-07-19 16:27:53

回答

0

你可以試試這個

$(document).ready(function() { 
    $('div').hover(function() { 
     $("ul li").eq($(this).index()).trigger("mouseover"); 
    }, function() { 
     $("ul li").eq($(this).index()).trigger("mouseout"); 
    }); 

    $('ul li').hover(function() { 
     $(this).css('background-color', 'red'); 
    }, function() { 
     $(this).css('background-color', 'white'); 
    }); 
});​ 

http://jsfiddle.net/LN2VL/

+0

感謝您填補這些缺失的部分。我必須修改您的代碼以便在將來添加或重新排序新項目時更具體。但是我仍然無法逆轉這種方法。我還需要網格來突出顯示鏈接何時懸停。 http://jsfiddle.net/LN2VL/19/ – 2012-07-19 17:25:18

+1

所以你想要這樣的東西? http://jsfiddle.net/LN2VL/24/ – 2012-07-19 17:45:20

+0

看起來不錯。謝謝有點。 – 2012-07-19 19:07:34

1

沒有嘗試過,但是這可能工作:

$('.count1').hover(function(){ 
    $('#item77').addClass('highlight'); 
}, function(){ 
    $('#item77').removeClass('highlight'); 
}); 
相關問題