該腳本在FF和IE中非常完美,但不適用於Chrome。有人可以幫助醫生找到問題嗎?Chrome爲什麼不運行這個Javascript?
如果statmenst似乎沒有運行時,他們應該,他們什麼時候應該。
var top = 285;
var bottom = 650;
var pageheight, maxscroll;
window.onload = function(){
pageheight = document.body.offsetHeight;
maxscroll = pageheight - (bottom+40);
}
window.onscroll = function(){
var element = document.getElementById("guide-menu");
if(window.pageYOffset < top){
element.style.position = "absolute";
element.style.top = "300px";
}
if(window.pageYOffset > top){
element.style.top = "10px";
element.style.position = "fixed";
element.style.marginTop = "0px";
}
if(window.pageYOffset > maxscroll){
element.style.position = "absolute";
element.style.marginTop = (pageheight - bottom - 40) + "px";
}
}
什麼是top top和maxscroll的值? –
這不是標準屬性,[MDN](https://developer.mozilla.org/en-US/docs/DOM/window.scrollY)可能會有所幫助。 – RobG