检测并处理滚动到页面底部事件

发布于 2024-11-19 19:11:36 字数 214 浏览 6 评论 0原文

http://dabbler.org/home/asdf/scrolling/test.html

有人看到这段代码有什么问题吗?

我不明白它有什么问题,但我的意图是当用户点击页面底部时,页面滚动到顶部。

谢谢。

http://dabbler.org/home/asdf/scrolling/test.html

Does anyone see anything wrong with this code?

I can't figure out what is wrong with it, but my intentions are such that when the user hits the bottom of the page, the page scrolls to the top.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谈场末日恋爱 2024-11-26 19:11:36

您错过了右括号:

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 compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var scrolledtonum = window.pageYOffset + myHeight - 16;
    var heightofbody = document.body.offsetHeight;
    if (scrolledtonum = heightofbody) {
        alert('asdf!')
    }

//???? } <--

这是一个包含一些代码修复的工作版本: http://jsfiddle.net/maniator/ 8mg/

You missed a closing parenthesis:

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 compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    var scrolledtonum = window.pageYOffset + myHeight - 16;
    var heightofbody = document.body.offsetHeight;
    if (scrolledtonum = heightofbody) {
        alert('asdf!')
    }

//???? } <--

Here is a working version with some code fixes: http://jsfiddle.net/maniator/8zhmg/

仄言 2024-11-26 19:11:36

在你的最后一行,你

if (scrolledtonum = heightofbody)

应该

if (scrolledtonum == heightofbody)

不确定这是否会成为问题

On your last line you have

if (scrolledtonum = heightofbody)

That should be

if (scrolledtonum == heightofbody)

Not sure if that'll be the problem though

静谧幽蓝 2024-11-26 19:11:36

您的函数缺少结束标签! (最后!)

啊..@Neal 打败了我!

Your missing a closing tag on your function! (at the very end!)

Argh.. @Neal beat me to it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文