感謝每一位對我的問題感興趣的人。 我在想這是一個CSS問題或HTML錯誤,但我用小jQuery代碼修復它。 另請參閱working example
jQuery(function(){
jQuery.miniMenu = new Object();
jQuery.miniMenu.i = new Object();
jQuery(document).on("scroll", function(){
var scroll_position = jQuery(window).scrollTop();
var doc_height = jQuery(document).height();
var w_height = jQuery(window).height();
var b_h = doc_height-w_height;
var scroll = (scroll_position/b_h)*100;
jQuery.miniMenu.i.globalVar = scroll;
console.log("scroll position "+scroll);
});
jQuery(window).click(function(){
console.log("new scroll "+jQuery.miniMenu.i.globalVar);
var scroll_position = jQuery(window).scrollTop();
var doc_height = jQuery(document).height();
var w_height = jQuery(window).height();
var b_h = doc_height-w_height;
var scroll = (scroll_position/b_h)*100;
console.log("scroll position "+scroll);
});
jQuery(window).on('orientationchange', orientationChangeHandler);
console.log("orentation change");
function orientationChangeHandler(e) {
setTimeout(function() {
var doc_height = jQuery(document).height();
var scroll = jQuery.miniMenu.i.globalVar;
var w_height = jQuery(window).height();
var b_h = doc_height-w_height;
var scroll_position = (scroll*b_h)/100;
scroll_position = Math.round(scroll_position);
jQuery('html, body').animate({scrollTop: scroll_position}, "5", function(){
console.log("animation complete");
});
console.log(scroll_position);
}, 20);
}
});