1
我想建立一個菜單欄彈性滾動和菜單欄就像你看到她的jsfiddle:錯誤與JS
http://jsfiddle.net/gvjeyywa/21/
有它的工作原理正是我想要它......但在途中網頁它有一個錯誤,我認爲這是因爲OSX的彈性滾動...在向下滾動菜單欄時,應從頂部滑入以設置頂部:0px,在那裏修復...但如果您滾動回頂部,彈性滾動卷軸高於身體...菜單跳得太高...
在這裏看到現場的例子: http://www.cyrill-kuhlmann.de/index.php/projects
在iOS上它是一個完整的混亂太...
這裏是JS代碼:
var bitFlag = false;
var isActive = true;
var lastScrollTop = 0;
var timeoutId;
$navigation = $("#navigation");
$(window).scroll(function (event) {
var intWindowTop = $(window).scrollTop();
var intElementBottom = $navigation.offset().top + $navigation.height();
if (intWindowTop > lastScrollTop) {
isActive = true;
if (!bitFlag) {
$navigation.css("position", "absolute").css("top", intWindowTop + "px");
bitFlag = true;
}
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(function() {
if (intWindowTop > intElementBottom) {
intDelayTime = setTimeout(function() {
if (isActive) {
$navigation.animate({ top: intWindowTop + "px" }, {
duration: 800,
step: function() {
if ($(window).scrollTop() < $navigation.offset().top) {
$(this).stop(true,true);
}
},
complete: function() {
intDelayTime2 = setTimeout(function() {
$("#navigation").css("position", "fixed").css("top", "0px");
bitFlag = false;
isActive = false;
}, 1);
}
});
}
}, 500);
}
}, 100);
} else {
$navigation.css("position", "fixed").css("top", "0px");
bitFlag = false;
isActive = false;
}
lastScrollTop = intWindowTop;
});
這是CSS:
#navigation {
position:absolute;
top: 0px;
left: 0px;
right: 0px;
height: 80px;
background-color: #FFF;
z-index:999;
padding-top: 25px;
padding-left: 45px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
是否有人有想法?不幸的是,我是一個在JS的血腥起動器...我很感謝任何幫助...
是的,這是它!完善! – Cyrill 2014-09-04 11:26:44
現在完美工作...在Ipad上它仍然是一團糟,但我認爲這也是可以解決的 – Cyrill 2014-09-04 11:29:40
據我所知,當您滾動時,ipad滾動事件不會被觸發,但當滾動停止時。因此可能會修復移動設備(或觸摸設備?)的元素並跳過此efx? – honk31 2014-09-04 12:52:24