2010-11-21 4 views
0

私がdivをドラッグすると、画像のタイトルが表示され、日付が10px移動します。私のコードでは、タイトルだけを表示しますが、日付部分は移動しません。 2つのjqueryアニメーションアクションをすべてうまく実行させる方法Thax。2つの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

関連する問題