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');
});

ホバーには 2callbacksつあり、1 つはあなたの場合に発火し、 2 つ目は の場合にhover発火しますhoverOut

于 2013-02-20T12:16:11.357 に答える
0

多分何かのような

$(".div1-child").hover(
  function () {
    $(this).find('.div1-sub-child').css(*** your new css ***);
  });
于 2013-02-20T12:13:47.927 に答える
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 に答える
0

これは、jquery と php を使用している場合に頻繁に発生します。これを行う方法はたくさんあります。ここでは、そのうちの 1 つを追加します。お役に立てば幸いです。

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

于 2013-03-19T07:27:35.420 に答える
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 に答える