jQuery 淡出一个图像到另一个图像的实现代码
发布时间:2014-01-22 编辑:jiaochengji.com
这篇文章主要介绍了jquery的hover事件实现两个图片的淡出切换效果,需要的朋友可以参考下
jquery 淡出一张图片到另一张图片,例如有下边的 html:
<div class="fade">
<img src="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="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学习
复制代码 代码如下:
<div class="fade">
<img src="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="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学习
您可能感兴趣的文章:
jQuery 淡出一个图像到另一个图像的实现代码
jQuery图片预览插件 Jquery Fade In.Fade Out
jQeury淡入淡出需要注意的问题
jQuery幻灯片插件 Slides
php image图像函数集
HTML5 canvas如何实现马赛克的淡入淡出效果(代码)
jQuery 淡入淡出 png图在ie8下有黑色边框的解决方法
jquery插件lazyload.js延迟加载图片的使用方法
PHP如何裁剪图片成固定大小
jQuery图像边框插件 Inset Border Effect
上一篇:Jquery 表单验证类介绍与实例
下一篇:jQuery插件的写法分享
[关闭]