これがサンプル構造です!
<div id ="div1">
<div class="div1-child">
<div class="div1-sub-child">
</div>
</div>
</div>
div1にカーソルを合わせたときに、div1-sub-childにjquery効果を適用する方法を教えてください。
これがサンプル構造です!
<div id ="div1">
<div class="div1-child">
<div class="div1-sub-child">
</div>
</div>
</div>
div1にカーソルを合わせたときに、div1-sub-childにjquery効果を適用する方法を教えてください。
これを行うために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
})
試す
$("#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
。
多分何かのような
$(".div1-child").hover(
function () {
$(this).find('.div1-sub-child').css(*** your new css ***);
});
div に特別なスタイルを追加するには、次を試してください。
$("#div1").hover(
function () {
$(this).find('div.div1-sub-child').addClass("hover");
},
function () {
$(this).find('div.div1-sub-child').removeClass("hover");
}
);
これは、jquery と php を使用している場合に頻繁に発生します。これを行う方法はたくさんあります。ここでは、そのうちの 1 つを追加します。お役に立てば幸いです。
$('#div1 .div1-child').children().addClass('addclass');
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
})