Home > Web Front-end > JS Tutorial > body text

jQuery implementation code to fade out one image to another_jquery

WBOY
Release: 2016-05-16 17:32:33
Original
936 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template