2012-01-14 57 views
3

我試圖寫入身體高度的50%作爲加法:.scrollTop() + 50%}而不是.scrollTop() + 200}因此,當鼠標離開#tail div時,會回到窗口高度的一半。偏移半窗口高度

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

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

什麼是正確添加百分比值的方法?

謝謝

回答

4

你可以試試這個。

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