当我将鼠标悬停在树的图像上时,我想要的是出现一个文本块,这已经可以工作了,但我希望文本块可以轻松地显示出来。这就是我已经拥有的功能,它是有效的,只是不是简单的部分:
HTML:
<p id="hover-text1" class="hover-text1"> Accomplished! </p>
<img id="tree_image1" class="tree_image1" src="/Tree-red.png">CSS:
.hover-text1 {
display: none;
transition: .5s all ease;
}
.tree_image1:hover {
opacity: 0.3;
}JS (它是我的HTML文件的头部):
<script type="text/javascript">
$(document).ready(function(){
$('#tree_image1').mouseenter(function(){
$('#hover-text1').css({'display':'block'});
});
$('#tree_image1').mouseleave(function(){
$('#hover-text1').css({'display':'none'});
});
});
</script>因此,当您将鼠标悬停在tree_image1上时,将出现文本块hover -TEX1,当您用鼠标离开图像时,该文本块将消失。但我希望这段文字以0.5s的速度显示,但我现在使用的方式不起作用。有人能帮上忙吗?
另外,我使用的是本地服务器,node js,ejs和express,也许这很重要。
发布于 2020-05-16 00:26:21
Display不是用于进行转换的属性之一。您可以通过转换到可见性和不透明度来实现这一点
<div class="wrapper">
<p class="hover-text1"> Accomplished! </p>
<img id="tree_image1" class="tree_image1" src="/Tree-red.png">
</div>
.hover-text1 {
visibility: hidden;
opacity: 0;
transition: visibility 2s, opacity 2s linear;
}
.tree_image1:hover {
opacity: 0.3;
}
.wrapper:hover .hover-text1 {
visibility: visible;
opacity: 1;
}发布于 2020-05-16 00:31:22
您可以使用jQuery的fadeIn/fadeOut来实现同样的目的
$(document).ready(function(){
$('#tree_image1').mouseenter(function(){
$('#hover-text1').fadeIn(500);// 500 - time interval
});
$('#tree_image1').mouseleave(function(){
$('#hover-text1').fadeOut(500);
});
});https://stackoverflow.com/questions/61823762
复制相似问题