1

这是样本结构!

<div id ="div1">
    <div class="div1-child">
        <div class="div1-sub-child">
        </div>
    </div>
 </div>

当我悬停 div1 时,谁能帮助我如何在 div1-sub-child 上应用 jquery 效果?

4

6 回答 6

1

你不需要 jquery 来做到这一点。只使用 css 就可以了。如下 -

#div1:hover .div1-sub-child {
   background-color:yellow
}

使用 jQuery -

$('#div1').hover({function(){  //this is called whn mouse enters the div
    $(this).find('.div1-sub-child').css('background-color','red'); //your effect here
},function(){   //this is called whn mouse leaves the div
    $(this).find('.div1-sub-child').css('background-color','green'); //your effect here
})
于 2013-02-20T12:12:40.940 回答
1

尝试

$("#div1").hover(
function()
{
    $(this).find('div.div1-sub-child').filter(':not(:animated)').animate(
    {
        marginLeft:'9px'
    },'slow');
},
function()
{
    $(this).find('div.div1-sub-child').animate(
    {
        marginLeft:'0px'
    },'slow');
});

Hover 有两种callbacks,一种是你时会开火,另一种是当你hover开火时hoverOut

于 2013-02-20T12:16:11.357 回答
0

当您使用 jquery 和 php 时,这很常见。并且有很多方法可以做到这一点,我将添加其中一种。希望这可以帮助您。

$('#div1 .div1-child').children().addClass('addclass');

于 2013-03-19T07:27:35.420 回答
0

也许像

$(".div1-child").hover(
  function () {
    $(this).find('.div1-sub-child').css(*** your new css ***);
  });
于 2013-02-20T12:13:47.927 回答
0

使用 jQuery

 $('#div1').hover({function(){  //this is called whn mouse enters the div
        $(this).find('.div1-sub-child').css('background-color','red'); //your effect here
    },function(){   //this is called whn mouse leaves the div
        $(this).find('.div1-sub-child').css('background-color','green'); //your effect here
  })
于 2013-02-20T12:16:20.667 回答
0

要为 div 添加特殊样式,请尝试:

$("#div1").hover(
  function () {
    $(this).find('div.div1-sub-child').addClass("hover");
  },
  function () {
    $(this).find('div.div1-sub-child').removeClass("hover");
  }
);
于 2013-02-20T12:26:59.220 回答