偏移半窗高度

时间:2012-01-14 04:37:11

标签: jquery

我试图写出50%的身高作为加法:.scrollTop() + 50%}而不是.scrollTop() + 200}所以当鼠标离开#tail div时会快速回到窗口高度的一半。

    .bind('mouseleave', function(){
     $('#wrapper').unbind('mousemove');

          $('#tail').animate({top:$('body').scrollTop() + 50%},300)   
});

添加百分比值的正确方法是什么?

由于

1 个答案:

答案 0 :(得分:5)

你可以试试这个。

.bind('mouseleave', function(){
     $('#wrapper').unbind('mousemove');
          var half_height = $(window).height()/2;
          $('#tail').animate({top: half_height},300)   
});