绑定'滚动'不会'我在IE 11中不工作

bind on 'scroll' doesn't work in IE 11

本文关键字:工作 不会 滚动 绑定 我在 IE      更新时间:2023-09-26

我有一个Angular指令,它需要对ELEMENT上的滚动事件执行某些操作(请不要在文档上说要执行此操作。这不是一个选项)。这个元素上的CSS有"overflow-y:visible",所以我现在改为"overflow:auto"进行测试。在IE 11上,我无法触发滚动事件,但在Chrome中,一切都很好。

app.directive('infiniteScroller', ['$document', function($document){
    return {
        restrict: 'AE',
        link: function($scope, $element, $attrs){
            var elm = document.querySelector('.class-for-some-div');
            var elm2 = $($element).closest('.class-for-some-div');
            console.log('infiniteScroller initialized, querysel, jquery', elm, elm2);
            elm.onscroll = function(event) {
                console.log('in bind scroll');
            };
            elm.addEventListener('scroll', function() {
                console.log('addEventListener scroll');
            },false);
            // elm.attachEvent('onscroll',function() {
            //     console.log('attachEvent onscroll');
            // });  //doesn't work on Chrome or IE
            elm2.bind('DOMMouseScroll', function() {
                console.log('bind DOMMouseScroll');
            });
            elm2.bind('wheel', function() {
                console.log('bind wheel');
            });
            // elm2.bind('scroll', function() {
            //     console.log('bind scroll');
            // });
        }
    };
}]);

正如你所看到的,我正在尝试各种各样的东西,但在IE中只有"轮子"事件控制台。其他人都没有。为什么IE不触发"滚动"事件,而只触发"轮子"活动?我只在IE控制台上看到"绑定轮子"。还对其他IE版本(9+)中的功能感兴趣。请帮忙。

我在IE中遇到了类似的问题。

看起来,当具有水平滚动的div的内容不可见时,事件就不会启动。不工作示例:

<div class="horizontal_scroller_container" style="width:500px;">
    <div class="horizontal_scroller" style="height:17px;overflow:scroll;">
        <div style="width: 6450px;">&nbsp;</div>
    </div>
</div>

工作示例:

<div class="horizontal_scroller_container" style="width:500px;">
    <div class="horizontal_scroller" style="overflow:scroll;">
        <div style="width: 6450px; height:1px;">&nbsp;</div>
    </div>
</div>

这是一把小提琴,展示了问题和解决方案:https://jsfiddle.net/1zzgnec6/3/