当我在下拉列表中滚动时,如何防止父div也滚动。有没有办法在jquery或javascript上执行此操作?我这样做了:
$('#scrollableDropdown').bind('mousewheel', function (e) {
var e0 = e.originalEvent,
delta = e0.wheelDelta || -e0.detail;
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();
});
但我认为它只适用于阻止身体滚动..
答案 0 :(得分:1)
如下所示调用函数名cancelBubble,它将停止事件冒泡。
$('#scrollableDropdown').bind('mousewheel', function (e) {
var e0 = e.originalEvent,
delta = e0.wheelDelta || -e0.detail;
this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
cancelBubble(e)
});
function cancelBubble(e) {
var evt = e ? e : window.event;
if (evt.stopPropagation) evt.stopPropagation();
if (evt.cancelBubble != null) evt.cancelBubble = true;
}