Как совместить два анимированных действия jQuery? - PullRequest
0 голосов
/ 22 ноября 2010

когда я наведу курсор мыши на div, он покажет заголовок изображения, затем дата переместится на 10 пикселей. В моем коде это просто показывает заголовок, но не перемещает часть даты. Как сделать так, чтобы два jquery animate action все работали хорошо? 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> 

1 Ответ

1 голос
/ 22 ноября 2010
$(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' });
             }
        );
   });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...