How to create javascript function for hovering 3 or 4 element at a time

前端 未结 2 1549
天涯浪人
天涯浪人 2021-01-27 22:37

I want to hover 3 item at a time. when i will put cursor one of them. It should hover other two item. please can help me anyone. i want to do this with javascript. I have make

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 23:07

    If you group your divs by parent divs, you can use the HTML structure to determine what to highlight. I don't know your exact usage model, but something like this:

    
    
    
    

    And then in your jQuery:

    $(document).on('mouseover', '.hover', function () {
        var boxgroup = $(this).closest('.boxgroup');
        boxgroup.find('.hover').addClass('hovercolor');
        boxgroup.find('.hov').css('color', '#0f0');
    }).on('mouseout', '.hover', function () {
        var boxgroup = $(this).closest('.boxgroup');
        boxgroup.find('.hover').removeClass('hovercolor');
        boxgroup.find('.hov').css('color', '#000');
    });
    

    Here, I use .closest() to find what group the div is in, and then highlight all of the other .hover items in that group.

    Example:

    http://jsfiddle.net/jtbowden/HZtVP/3/

    If you want your divs to not be physically grouped, there are other ways to do what you want.

提交回复
热议问题