jqueryangularjs如何知道鼠标按下事件是否是由浏览器的滚动条触发的

jquery angularjs how to know if mouse down event is trigger by scrollbar of browser

本文关键字:浏览器 滚动条 是否是 事件 何知道 鼠标 jqueryangularjs      更新时间:2024-03-01

我有一个小面板,如果在该面板之外的任何地方按下鼠标向下键,我都会关闭它,基本上它会清除要显示的数据,并且在angularjs ng show的帮助下,如果没有数据,我会隐藏它。。。应用程序在angularjs和jquery 中

请在下面找到代码

 var closeSearchResultsIfClickedOutside = function (e) {
    if ($(e.target).parents('.searchResults').length === 0) {
        var scope = angular.element($("#searchContainer")).scope();
        scope.$apply(function () {
            /*Cancels any existing search*/
            if ($scope.defer != undefined) {
                $scope.defer.resolve();
            }
            $scope.showSearchResults = false;
            reinitialize();                
        });
        $("html").off("mousedown", closeSearchResultsIfClickedOutside);
        reinitializePanelsWidth();
    }      
};

但如果鼠标在浏览器窗口的滚动条或任何滚动条上,我不想关闭这个面板。。请告诉我如何进行

要解决上述问题,我没有捕获两个事件,请向下鼠标单击,如果两个事件上的目标元素匹配,则只有我关闭面板。

 /*
  If mouse down and click on the same control, then only close the panel,
  Click event closing is added to avoid closing panel on scrollbar click.  
*/
var closeSearchResultsIfClickedOutside = function (e) {
    if (e.type === 'mousedown') { /* only if mouse down is outside of search panel then only close the panel. */
        if($(e.target).parents('.searchResults').length === 0)
        {
            isMouseDownOnSearchPanel = true;
        }
    else {
            isMouseDownOnSearchPanel = false;
        }
    }
    else if (e.type === 'click' && isMouseDownOnSearchPanel) {  /*click event is implemented to avoid closing when mouse down is on scrollbar. you dont get click get event for scrollbar*/
        var scope = angular.element($("#searchContainer")).scope();
        $("html").off("mousedown", closeSearchResultsIfClickedOutside);
        $("html").off("click", closeSearchResultsIfClickedOutside);
        isMouseDownOnSearchPanel = false;
        reinitializePanelsWidth();
    }       
};