简体   繁体   English

淡入淡出div悬停

[英]Fade div on hover

I have a div that contains an image, when you hover over it another div appears containing text. 我有一个包含图像的div,当您将鼠标悬停在其上时,会出现另一个包含文本的div。 Is there a way (using jquery or CSS) to add a fade effect? 有没有一种方法(使用jquery或CSS)添加淡入淡出效果?

Heres the code im using... 继承人代码使用...

.work_box1, .work_box2, .work_box3 {
    display: inline-block;
    height: 324px;
    width: 324px;
}
.work_title {
    display: none;
    height: 100%;
    width: 100%;
}
.work_box1:hover > .work_title, .work_box2:hover > .work_title, .work_box3:hover > .work_title {
    display: block;
}

here's my go at it: http://jsfiddle.net/5c324/1/ 这是我的努力: http : //jsfiddle.net/5c324/1/

$("#myBox").mouseenter(function() {
     $( "#myBox" ).fadeTo( "slow" , 0.5, function() {});
});

$("#myBox").mouseout(function() {
     $( "#myBox" ).fadeTo( "slow" , 1.0, function() {});
});

CSS3 transitions can do that. CSS3过渡可以做到这一点。 But for older browsers that can't do it without JS here's a jQuery solution: 但是对于没有JS无法做到的旧版浏览器,这是一个jQuery解决方案:

$(".work_title").parent().hover(function() {
    $(this).find(".work_title").fadeIn();
}, function() {
    $(this).find(".work_title").fadeOut();
});

Demo: http://jsfiddle.net/bddde/ 演示: http//jsfiddle.net/bddde/

If I understand correctly, the work_title class is applied to the text annotations that overlay your images. 如果我理解正确,则将work_title类应用于覆盖您的图像的文本注释。 In that case, you can use CSS3 transitions to fade them in and out when the mouse moves over them. 在这种情况下,当鼠标移到CSS3过渡上时,可以使用它们过渡淡入和淡出。

.work_title {
    display: block;
    opacity: 0.0;
    height: 100%;
    width: 100%;
}
.work_title:hover {
    opacity: 1.0;
    transition: opacity 0.3s ease;
    -webkit-transition: opacity 0.3s ease;
}

If you want to support IE8, you'll have to include rules for filter as well as opacity -- I'll leave you to figure out how to do this :-) 如果要支持IE8,则必须包括filter规则和opacity -我将让您找出如何执行此操作的方法:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM