简体   繁体   English

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

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

I have a small panel which i close if mouse down button is pressed anywhere else than that panel, basically it clears the data to display and just with the help of angularjs ng-show i hide it if there is no data...application is in angularjs and jquery 我有一个小面板,如果在该面板以外的任何地方按下鼠标按钮,我关闭,基本上它清除要显示的数据,只是在angularjs ng-show的帮助下我隐藏它,如果没有数据...应用程序是在angularjs和jquery中

please find the code below 请找到下面的代码

 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();
    }      
};

but i dont want to close this panel if mouse down is on scrollbar of browser window or any scrollbar..please tell me how to do that 但我不想关闭此面板,如果鼠标按下浏览器窗口的滚动条或任何滚动条..请告诉我如何做到这一点

to fix the above problem i am not capturing both event, mouse down and click, if the target element on both event matches then only i am closing the panel. 解决上述问题我没有捕获事件,鼠标按下并单击,如果两个事件上的目标元素匹配,那么我只关闭面板。

 /*
  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();
    }       
};

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

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