亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery 淡出一個圖像到另一個圖像的實現(xiàn)代碼

 更新時間:2013年06月12日 12:34:14   作者:  
這篇文章主要介紹了jquery的hover事件實現(xiàn)兩個圖片的淡出切換效果,需要的朋友可以參考下
jQuery 淡出一張圖片到另一張圖片,例如有下邊的 html:

復(fù)制代碼 代碼如下:

<div class="fade">
<img src="1.jpg" />
</div>


首先,確保 div 的大小和圖片大小一樣,這個 div 有另一個背景圖,如下:

css代碼:

復(fù)制代碼 代碼如下:

.fade
{
background-image:url('images/2.jpg');
width:300px;
height:225px;
}


jQuery 代碼如下:

復(fù)制代碼 代碼如下:

$(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);
});
});


完整實現(xiàn)代碼:

復(fù)制代碼 代碼如下:

<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學(xué)習(xí)

相關(guān)文章

最新評論