有几个属性可以获取页面滚动,并且在每个浏览器中都不同。这是我为接收正确滚动而编写的函数:
函数getScroll(类型)
{
类型 = 类型 || '最佳';
变量结果 = 0;
变量滚动 = 0;
如果(类型==='顶部')
{
if (ISQ.Http.browser.app !== 'ie' || ISQ.Http.browser.isIE9)
滚动 = window.pageYOffset;
if (ISQ.Http.browser.app !== 'ie')
scroll = returnMaxScroll(scroll, window.scrollY);
scroll = returnMaxScroll(scroll, document.body.scrollTop);
scroll = returnMaxScroll(scroll, document.documentElement.scrollTop);
scroll = returnMaxScroll(scroll, document.body.parentNode.scrollTop);
}
else if (type === 'left')
{
if (ISQ.Http.browser.app !== 'ie' || ISQ.Http.browser.isIE9)
滚动 = window.pageXOffset;
if (ISQ.Http.browser.app !== 'ie')
scroll = returnMaxScroll(scroll, window.scrollX);
scroll = returnMaxScroll(scroll, document.body.scrollLeft);
scroll = returnMaxScroll(scroll, document.documentElement.scrollLeft);
scroll = returnMaxScroll(scroll, document.body.parentNode.scrollLeft);
}
else if (type === '身高')
{
开关(ISQ.Http.browser.app)
{
案例“铬”:
案例“ff”:
案例“歌剧”:
案例“野生动物园”:
// iframe
如果(window.top === 窗口)
滚动 = document.documentElement.scrollHeight;
// 顶部窗户
别的
滚动 = document.body.scrollHeight;
休息;
默认:
scroll = returnMaxScroll(scroll, document.body.scrollHeight);
scroll = returnMaxScroll(scroll, document.documentElement.scrollHeight);
scroll = returnMaxScroll(scroll, document.body.parentNode.scrollHeight);
休息;
}
}
否则如果(类型==='宽度')
{
scroll = returnMaxScroll(scroll, document.body.scrollWidth);
scroll = returnMaxScroll(scroll, document.documentElement.scrollWidth);
scroll = returnMaxScroll(scroll, document.body.parentNode.scrollWidth);
}
返回滚动;
}
函数 returnMaxScroll(value1, value2)
{
if (value1 > value2) 返回值1;
返回值2;
}
仅供参考:您可能需要实现这些布尔值:
- ISQ.Http.browser.app !== 'ie'
- ISQ.Http.browser.isIE9
我希望它会帮助你:)