源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jQuery 淡出一个图像到另一个图像的实现代码

  • 时间:2022-10-02 23:56 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jQuery 淡出一个图像到另一个图像的实现代码
jQuery 淡出一张图片到另一张图片,例如有下边的 html:
[u]复制代码[/u] 代码如下:
<div class="fade"> <img src="1.jpg" /> </div>
首先,确保 div 的大小和图片大小一样,这个 div 有另一个背景图,如下: css代码:
[u]复制代码[/u] 代码如下:
.fade { background-image:url('images/2.jpg'); width:300px; height:225px; }
jQuery 代码如下:
[u]复制代码[/u] 代码如下:
$(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); }); });
完整实现代码:
[u]复制代码[/u] 代码如下:
<div class="fade"><img src="1.jpg" /></div> <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学习
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部