【问题标题】:jQuery scroll event is not working IE 9jQuery 滚动事件不起作用 IE 9
【发布时间】:2014-10-21 09:15:22
【问题描述】:

我有这个 JS:

$(document).ready(function () {
    var scrollMenu = $("#list .side-nav"),
        scrollMenuFixed = false;

        $(window).scroll(function() {
            var scrolled = window.pageYOffset || document.documentElement.scrollTop;

            if (scrolled > 200 && !scrollMenuFixed) {
                scrollMenu.addClass("fixed");
                scrollMenuFixed = true;
            }
            else if (scrolled <= 200 && scrollMenuFixed) {
                scrollMenu.removeClass("fixed");
                scrollMenuFixed = false;
            }
        });
});

它在 IE +9 FF 和 Chrome 等上运行良好。但在 IE9 中没有人知道这个问题吗?

注意:事件在页面加载时注册。

【问题讨论】:

  • 尝试使用 jQuery scrollTop() 属性,因为它应该是跨浏览器兼容的:var scrolled = $(this).scrollTop();

标签: javascript jquery internet-explorer-9 compatibility


【解决方案1】:

$(window).scroll() 更改为 $('html,body').scroll() 成功了,它现在可以工作了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 2012-01-21
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    相关资源
    最近更新 更多