2010-11-21 2 views
0

Когда я навешиваю указатель на div, он покажет название изображения, затем дата переместится на 10 пикселей. В моем коде он просто показывает название, но не перемещает дату. Как сделать два действия анимации jquery, все работает хорошо? Thax.Как объединить два действия анимации jQuery?

<!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
$(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' }); 
      } 
     ); 
    }); 
}); 
+0

Великий, правильный путь должен быть написан так. –

+1

Вы говорите, что это работает? Если да, примите ответ! – Eric

Смежные вопросы