admin管理员组文章数量:1399313
Does anyone have any idea why the following script does not reset the place of the page to the top? (The autoscrolling works fine) I am look for the fix to be patable in IE...
function getheight() {
var myWidth = 0,
myHeight = 0;
if (typeof (window.innerWidth) == 'number') {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards pliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 patible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
var scrolledtonum = window.pageYOffset + myHeight + 2;
var heightofbody = document.body.offsetHeight;
if (scrolledtonum >= heightofbody) {
document.body.scrollTop(0, 0);
}
}
window.onscroll = getheight;
function func() {
window.document.body.scrollTop++;
}
window.document.onmouseover = function () {
clearInterval(interval);
};
window.document.onmouseout = function () {
interval = setInterval(func, 20);
};
var interval = setInterval(func, 20);
Does anyone have any idea why the following script does not reset the place of the page to the top? (The autoscrolling works fine) I am look for the fix to be patable in IE...
function getheight() {
var myWidth = 0,
myHeight = 0;
if (typeof (window.innerWidth) == 'number') {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards pliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 patible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
var scrolledtonum = window.pageYOffset + myHeight + 2;
var heightofbody = document.body.offsetHeight;
if (scrolledtonum >= heightofbody) {
document.body.scrollTop(0, 0);
}
}
window.onscroll = getheight;
function func() {
window.document.body.scrollTop++;
}
window.document.onmouseover = function () {
clearInterval(interval);
};
window.document.onmouseout = function () {
interval = setInterval(func, 20);
};
var interval = setInterval(func, 20);
Share
Improve this question
asked Jul 18, 2011 at 15:55
OdinulfOdinulf
5812 gold badges7 silver badges19 bronze badges
1
- Check your css - by me the problem was that I had 'overflow: scroll' set to a child in the body, and not to the body/html itself, so I had to animate the child div and not the body/html (so instead of $('body, html').animate({ scrollTop: 0 }, "slow"); I had to do $('.child-element').animate({ scrollTop: 0 }, "slow"); ) – tsveti_iko Commented Sep 30, 2016 at 14:33
1 Answer
Reset to default 4In your code you have:
document.body.scrollTop(0, 0);
scrollTop is not a method call.
Did you mean window.scrollTo(0,0)
or document.body.scrollTop = 0;
?
本文标签: javascriptScrolltop not workingStack Overflow
版权声明:本文标题:javascript - Scrolltop not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744210941a2595414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论