无为清净楼资源网 Design By www.qnjia.com
jQuery 淡出一张图片到另一张图片,例如有下边的 html:

复制代码 代码如下:
<div class="fade">
<img src="/UploadFiles/2021-04-02/1.jpg"></div>


首先,确保 div 的大小和图片大小一样,这个 div 有另一个背景图,如下:

css代码:

复制代码 代码如下:
.fade
{
background-image:url('images/2.jpg');
width:300px;
height:225px;
}


jQuery 代码如下:

复制代码 代码如下:
$(document).ready(function () {
$(".fade").hover(function () {
$(this).find("img").stop(true, true).animate({ opacity: 0 }, 500);
}, function () {
$(this).find("img").stop(true, true).animate({ opacity: 1 }, 500);
});
});


完整实现代码:

复制代码 代码如下:
<div class="fade"><img src="/UploadFiles/2021-04-02/1.jpg"><style type="text/css">
.fade
{
background-image:url('2.jpg');
width:300px;
height:225px;
margin:0 auto 15px;
}</style>
<script type="text/javascript">
$(document).ready(function () {
$(".fade").hover(function () {
$(this).find("img").stop(true, true).animate({ opacity: 0 }, 500);
}, function () {
$(this).find("img").stop(true, true).animate({ opacity: 1 }, 500);
});
});
</script>


作者:jQuery学习
标签:
jQuery,淡出

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com