繁体   English   中英

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

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

我有一个Angular指令,该指令需要对ELEMENT上的scroll事件做一些事情(请不要说对文档执行此操作。这不是一个选择)。 此元素上的CSS具有“ overflow-y:可见”,因此我现在更改为“ 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中只有'wheel'事件console.logs,其他人都没有。 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/

暂无
暂无

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

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