发布于 2016-09-16 21:45:34 | 114 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的jQuery示例,程序狗速度看过来!

jQuery javascript框架

jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多)。jQuery在2006年1月由美国人John Resig在纽约的barcamp发布,吸引了来自世界各地的众多JavaScript高手加入,由Dave Methvin率领团队进行开发。


这篇文章主要介绍了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学习

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务