Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 元素未能在中使用scrollTop,即_Javascript - Fatal编程技术网

Javascript 元素未能在中使用scrollTop,即

Javascript 元素未能在中使用scrollTop,即,javascript,Javascript,我创建了一个事件监听器,它会导致一个溢出的下拉列表在按键下滚动事件监听器。需要覆盖一些讨厌的jQuery UI。除了在Internet Explorer中,所有这些都工作得非常好。。。以下是我的功能: function addKeyboardScroll(element) { element.addEventListener('keydown', e => { // find the select dropdown list, and if not enough items t

我创建了一个事件监听器,它会导致一个溢出的下拉列表在
按键下滚动
事件监听器。需要覆盖一些讨厌的jQuery UI。除了在Internet Explorer中,所有这些都工作得非常好。。。以下是我的功能:

function addKeyboardScroll(element) {
  element.addEventListener('keydown', e => {
    // find the select dropdown list, and if not enough items to have scrollable overflow return.
    const dropdown = element.querySelector('.choices__list--dropdown');
    if (!dropdown.scrollHeight) return;

    // find the select item that is highlighted, and if none exist return;
    const item = element.querySelector('.is-highlighted');
    if (!item) return;

    // We don't want to trigger scroll on placeholder select items as it will skew the scroll function.
    if (item.classList.contains('choices__placeholder')) return;
    if (e.key === 'ArrowDown') {
      dropdown.scrollTop += 30;
    } else if (e.key === 'ArrowUp') {
      dropdown.scrollTop -= 30;
    }
  });
}

在上,即从溢出元素中从未添加/减去像素,因此没有滚动。从我所有的研究中,我使用的所有东西都得到了支持,我确保给下拉列表一个
overflow:scroll
,以确保安全,但没有运气。试图使用ie检查员让我想挖出我的眼睛,因此感谢您的帮助。是否缺少关键字或需要额外步骤才能获得滚动操作,例如?

对于IE中较旧的doctype,您可能希望尝试此操作

var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
或者看看下面的IE源链接

参考文献: