更改图像并在悬停时淡入 [英] Change image and fadeIn on hover
本文介绍了更改图像并在悬停时淡入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
$('div.test').hover(function() {
$(this).find('img').attr('src', 'img/personale/test2.png');
}, function() {
$(this).find('img').attr('src', 'img/personale/test.png');
});
在悬停时更改图像时如何添加淡入效果?
How can i add a fadeIn effect while changing the image on hover?
推荐答案
Try using fadeIn()
and fadeOut()
:
$('div.test').hover(function () {
$(this).find('img').hide().attr('src', 'http://blog.stackoverflow.com/wp-content/uploads/StackExchangeLogo1.png').fadeIn(2000);
}, function () {
$(this).find('img').fadeOut(2000,function(){
$(this).attr('src','http://londontechnologyweek.co.uk/assets/uploads/2014/06/Stack-Overflow-Logo.png').fadeIn();
});
});
.test{
min-height:200px;
text-align:center;
border:1px solid;
}
.test img{
width:100%;
height:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">
<img src="http://londontechnologyweek.co.uk/assets/uploads/2014/06/Stack-Overflow-Logo.png"/>
</div>
这篇关于更改图像并在悬停时淡入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文