3
我試圖隱藏菜單當滾動達到150像素我的動畫滾動滯後,爲什麼
HTML:
<html>
<body style="height:2000px">
<div id="header">
</div>
</body>
</html>
CSS:
#header{height:200px; background:#000; position:fixed; top:0; width:100%;}
JS:
$(function(){
$(window).bind('scroll', function(){
if($(this).scrollTop() >= 150) {
$('#header').attr('data-open','open');
}
if($(this).scrollTop() >= 150 && $('#header').attr('data-open') == 'open'){
$("#header").animate({top:'-180px'},500, 'linear').attr('data-open','open');
}else{
$("#header").animate({top:'0'},500, 'linear').removeAttr('data-open');
}
});
});
演示:http://jsfiddle.net/egZ6H/1/
它似乎工作,但當我回到頂部時,有時顯示菜單的動畫開始有點太遲,反之亦然。
這是什麼原因造成的?
地獄啊!謝謝! – Warface 2012-02-21 14:55:51