javascript - 检测滚动到页面底部事件并采取行动

标签 javascript html css dhtml

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

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

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

谢谢。

最佳答案

你错过了一个右括号:

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/8zhmg/

关于javascript - 检测滚动到页面底部事件并采取行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6666617/

相关文章:

javascript - 将库导入到 vue.js 的单个文件组件中

javascript - 将 JavaScript 数组拆分成更小的数组并获取每个值的频率

html - 使用具有最大宽度的空白 nowrap

css - html 文件中缺少图像

css - 从顶部展开子菜单而不是下拉菜单

html - <table> 中的 Flex CSS 属性在 IE 和 Firefox 上不起作用

javascript - react : Pass function property down to pure child component - Rerendering

javascript - :hover is not working

jquery - 如何使用 jQuery 同时运行 `show` 和 `animate`?

css - 绝对或 float 的 UL 问题,链接不可点击