Home >Web Front-end >JS Tutorial >jQuery implementation code to fade out one image to another_jquery

jQuery implementation code to fade out one image to another_jquery

WBOY
WBOYOriginal
2016-05-16 17:32:33965browse

jQuery fades out one picture to another, for example, the following html:

Copy code The code is as follows:






First, make sure the size of the div is the same as the image size. This div has another background image, as follows:

css code:

Copy code The code is as follows:

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


jQuery code is as follows:

Copy code The code is as follows:

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


Complete implementation code:

Copy code The code is as follows:



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



Author : jQuery Learning
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn