How to combine two jQuery animate actions?
when I mouseover the div, it will show the image title, then the date will move 10px. In my code, it just show the ti开发者_运维技巧tle, but not move the date part. How to make two jquery animate action all run well? Thax.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(function() {
$('.image').each(function() {
$(this).hover(
function() {
$('.title', this).animate({ opacity: 1 })
},
function() {
$('.title', this).stop().animate({ opacity: 0 });
},
function() {
$('.date', this).animate({ top: '+=10' })
},
function() {
$('.date', this).stop().animate({ top: '-=10' });
})
});
});
</script>
</head>
<body>
<div class="image"><img src="img1.jpg"><p class="title">test1</p><p class="date">2010</p></div>
</body>
</html>
$(function() {
$('.image').each(function() {
$(this).hover(
function() {
$('.title', this).stop(1,1).animate({ opacity: 1 });
$('.date', this).stop(1,1).animate({ top: '+=10' });
},
function() {
$('.title', this).stop(1,1).animate({ opacity: 0 });
$('.date', this).stop(1,1).animate({ top: '-=10' });
}
);
});
});
精彩评论