Javascript 当鼠标位于子可滚动HTML元素上时,如何使用鼠标滚轮移动父滚动条?

Javascript 当鼠标位于子可滚动HTML元素上时,如何使用鼠标滚轮移动父滚动条?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有以下问题。我有一个父div,它包含几个子div。父级和子级都有滚动条。当我的鼠标在该元素上时,我只想移动父元素的滚动条,不管鼠标是否悬停在可滚动的子div上。换句话说,我希望阻止对子事件进行事件处理,并将事件传播到父事件。大概是这样的: <div id='parent' style='overflow-y:auto;height:200px;width:100%'> <div class='child' style='overflow-y:auto;height:1

我有以下问题。我有一个父div,它包含几个子div。父级和子级都有滚动条。当我的鼠标在该元素上时,我只想移动父元素的滚动条,不管鼠标是否悬停在可滚动的子div上。换句话说,我希望阻止对子事件进行事件处理,并将事件传播到父事件。大概是这样的:

<div id='parent' style='overflow-y:auto;height:200px;width:100%'>
    <div class='child' style='overflow-y:auto;height:100px'>
    </div>
    <div class='child' style='overflow-y:auto;height:100px'>
    </div>
    <div class='child' style='overflow-y:auto;height:100px'>
    </div>
</div>

<script>
    $('.child').bind('mousewheel DOMMouseScroll', function(e) {
        $(e.target).parent().trigger(e);
    });
</script>

$('.child').bind('mousewheel-DOMMouseScroll',函数(e){
$(e.target).parent().trigger(e);
});

注意:允许使用jQuery。

这是正确的解决方案,因为@DavidFregoli:

$('.child').on('mousewheel DOMMouseScroll', function(e) {
    var $div = $(this),
    $parent = $div.parent(),
    scrollAmount = 30,
    currentScroll = $parent.scrollTop(),
    newScroll = currentScroll + (e.originalEvent.wheelDelta < 0 ? scrollAmount : -scrollAmount);
    $parent.scrollTop(newScroll);
    return false;
});
$('.child').on('mousewheel-DOMMouseScroll',函数(e){
var$div=$(此),
$parent=$div.parent(),
滚动量=30,
currentScroll=$parent.scrollTop(),
newScroll=currentScroll+(e.originalEvent.wheelDelta<0?scrollAmount:-scrollAmount);
$parent.scrollTop(newScroll);
返回false;
});

整个代码是

像这样尝试就是这样!非常感谢。或者更简单一点,这也适用于ff@DavidFregoli您应该发布您的解决方案作为答案,包括代码。