/ / ako používať prechod CSS na zobrazenie bloku pri ukázaní na iný blok? - jquery

ako používať css Transition na zobrazovaní bloku, keď sa vznášate na inom bloku? - jQuery

HTML

<div class="onediv"><a href="">text</a></div>
<div class="nextdiv">
<p>testing testing testing testing testing testing testing testingtesting.
</p>
</div>

CSS

.nextdiv{display: none;}

jQuery

$( ".onediv a" ).hover(function() {
$(".nextdiv").css({"display" : "block"});
});

$( ".onediv a" ).mouseleave(function() {
$(".nextdiv").css({"display":"none"});
});

Keď ukážem kurzorom na text, zobrazí sa .nextdiv. Teraz chcem použiť prechod, keď sa zobrazí .nextdiv. vopred ďakujem.

odpovede:

2 pre odpoveď č. 1

$(".onediv").hover(function() {
$(this).next(".nextdiv").toggle("slow")
});
.nextdiv {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="onediv"><a href="">text</a>
</div>
<div class="nextdiv">
<p>testing testing testing testing testing testing testing testingtesting.
</p>
</div>

<div class="onediv"><a href="">text1</a>
</div>
<div class="nextdiv">
<p>text1 text1 text1 text1 text1 text1 text1 text1.
</p>
</div>

<div class="onediv"><a href="">text2</a>
</div>
<div class="nextdiv">
<p>text2 text2 text2 text2 text2 text2 text2 text2.
</p>
</div>

Popis: Zobraziť alebo skryť zhodné prvky.

  1. Môžeš použiť .Toggle()
  2. Presunutím kurzora umiestnite div na nie a

1 pre odpoveď č. 2

Namiesto použitia display:none, môžete použiť iné techniky na skrytie prvku, ako napríklad použitie negatívu z-index aby sa prechod prejavil, keď sa zobrazí:

$(".onediv a").hover(function() {
$(".nextdiv").addClass("show");
}, function() {
$(".nextdiv").removeClass("show");
});
.nextdiv {
position: absolute;
z-index: -999;
opacity: 0;
transition: all 1s;
}
.show {
position: static;
z-index: 0;
opacity: 1
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="onediv"><a href="">text</a>
</div>
<div class="nextdiv">
<p>testing testing testing testing testing testing testing testingtesting.
</p>
</div>