Javascript检测浏览器滚动到顶部? [英] Javascript detect browser scroll to the top?

查看:79
本文介绍了Javascript检测浏览器滚动到顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改以下代码以检测滚动到首页。

How do I modify the following code to detect scrolling to the top page instead.

window.onscroll = function(ev) {
    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        alert(bottom);
    }
};

编辑:

我正在努力用于Windows Phone 8的IE 10 BTW

I am working on IE 10 for Windows Phone 8 BTW

推荐答案

管理以解决问题。这是我的代码

Managed to figure it out. Here's my code

window.onscroll = function() {

    var body = document.body; //IE 'quirks'
    var document = document.documentElement; //IE with doctype
    document = (document.clientHeight) ? document : body;

    if (document.scrollTop == 0) {
        alert("top");
    }        
};

DEMO

这篇关于Javascript检测浏览器滚动到顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆