0

ここで少しn00b。リスト項目内で画像を配置してアニメーション化する、見つけたホバー機能を変更しようとしていました。.animate({top: 最初のインスタンスで正確なピクセル値を与える代わりに、含まれている li の高さを取得する変数 imgHeight を渡したかったのですが、明らかに何か間違ったことをしています。ポインタはありますか?

var imgHeight = $('li').height();
$(function() {
$('ul.hover_block li').hover(function(){
$(this).find('img').animate({top:'imgHeight' + 'px'},{queue:false,duration:200});
}, function(){
$(this).find('img').animate({top:'0px'},{queue:false,duration:200});
});
});​
4

1 に答える 1

0

代わりにこれを試してください:

{top: 'imgHeight' + 'px'}

する必要があります

{top: imgHeight + 'px'}

完全なコード:

var imgHeight = $('li').height();
$(function() {
        $('ul.hover_block li').hover(function(){
            $(this).find('img').animate({top:imgHeight + 'px'},{queue:false,duration:200});
        }, function(){
            $(this).find('img').animate({top:'0px'},{queue:false,duration:200});
      });
});​
于 2012-06-29T16:13:17.910 に答える