简体   繁体   English

在“滚动”上绑定在IE 11中不起作用

[英]bind on 'scroll' doesn't work in IE 11

I have an Angular directive that needs to do something on the scroll event on an ELEMENT (plz don't say to do this on document. not an option). 我有一个Angular指令,该指令需要对ELEMENT上的scroll事件做一些事情(请不要说对文档执行此操作。这不是一个选择)。 CSS on this element had "overflow-y: visible" so I changed to "overflow: auto" for now for testing. 此元素上的CSS具有“ overflow-y:可见”,因此我现在更改为“ overflow:auto”以进行测试。 On IE 11, I cannot trigger the scroll event but in Chrome, things are working fine. 在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');
            // });
        }
    };
}]);

As you can see, I'm trying all kinds of stuff but only 'wheel' event console.logs in IE and none others do. 如您所见,我正在尝试各种方法,但IE中只有'wheel'事件console.logs,其他人都没有。 Why does IE not trigger the 'scroll' event but only 'wheel' event? IE为什么不触发“滚动”事件而是仅触发“滚轮”事件? I only see 'bind wheel' on IE console. 我只在IE控制台上看到“绑定轮”。 Also interested in what works in other IE versions (9+). 也对其他IE版本(9+)中的功能感兴趣。 Please help. 请帮忙。

I had similar issue in IE. 我在IE中有类似的问题。

It looks like when the content of the div which has the horizontal scroll is not visible than event is not fired up. 看起来当具有水平滚动的div的内容不可见而不是事件未触发时。 Not working examle: 不工作的例子:

<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>

Working examle: 工作范例:

<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>

Here is a fiddle which shows the problem and the resolution: https://jsfiddle.net/1zzgnec6/3/ 这是一个显示问题和解决方法的小提琴: https : //jsfiddle.net/1zzgnec6/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM