简体   繁体   English

检测DIV下的项目

[英]Detect Items Under a DIV

I have a table on a screen on which I overlay a DIV to provide mouse click and move detection in order to resize columns on the table. 我在屏幕上有一个表格,在该表格上叠加了DIV,以提供鼠标单击和移动检测,以便调整表格上的列大小。

I have a column that has tags. 我有一列带有标签。 What is the best way to reflect mouse change events for items under the DIV? 反映DIV下项目的鼠标更改事件的最佳方法是什么? I can get the table item of course, as well as the rows and columns. 我当然可以得到表格项以及行和列。 But how do I allow anchor tags to work as if no DIV is overlayed? 但是,如何让锚标记像没有DIV一样工作?

        function handleResize(tableId, gripsId) {
        var tbl;
        var grips;
        var clicks = 0, delay = 400;
        var capture;
        var tbl;
        var head;
        var rows;
        var col;
        var posX;
        var offWidth;

        tbl = document.getElementById(tableId);
        grips = document.getElementById(gripsId);

        grips.addEventListener("wheel", function (e) {
            var body = tbl.children[1];
            body.scrollBy(0, e.deltaY);
        });

        grips.addEventListener("mousemove", mouseMove);

        grips.addEventListener("mousedown", function (e) {
            event.preventDefault();
            clicks++;

            setTimeout(function () {
                clicks = 0;
            }, delay);

            head = tbl.children[0].children[0];
            rows = tbl.children[1].children;
            col = parseInt(e.target.className);

            if (e.target.className != '') {
                if (clicks === 2) {
                    var width = head.cells[col].innerText.visualLength() + 20;
                    for (var row = 0; row < rows.length; ++row) {
                        var len = rows[row].innerText.toString().visualLength() + 15;
                        width = Math.max(width, len);
                    }

                    head.cells[col].style.minWidth = head.cells[col].style.maxWidth = width + 'px';
                    for (var row = 0; row < rows.length; ++row) {
                        var style = rows[row].cells[col].style;
                        style.minWidth = style.maxWidth = width + 'px';
                    }

                    recalcDivs(tbl, grips);
                }
                else {
                    posX = event.clientX;

                    offWidth = -$('#' + tableId).scrollLeft();
                    for (var i = 0; i < col; ++i)
                        offWidth += $rootScope.parseWidth(head.cells[i].style.minWidth);

                    capture = e.target;
                    $scope.left = $rootScope.parseWidth(capture.style.left);

                    grips.removeEventListener("mouseup", mouseUp);
                    grips.addEventListener("mouseup", mouseUp);
                }
            }
        });

        function mouseMove(e) {
            if (e.buttons == 0) {
                if ((event.clientY - tbl.getBoundingClientRect().top) < 20)
                    grips.style.cursor = 'pointer';
                else {
                    grips.style.cursor = 'default';

                }
                //grips.style.cursor = ((event.clientY - tbl.getBoundingClientRect().top) < 20) ? 'pointer' : 'default';
            }
            else if (e.buttons == 1) {
                var style = head.cells[col].style;
                $scope.offset = $scope.left - offWidth + (event.clientX - posX);
                style.minWidth = style.maxWidth = $scope.offset + 'px';

                for (var row = 0; row < rows.length; ++row) {
                    var style = rows[row].cells[col].style;
                    style.minWidth = style.maxWidth = $scope.offset + 'px';
                }

                capture.style.left = $scope.offset + 'px';
                tbl.children[1].style.height = screenHeight - rect.top - 80 - ((tbl.scrollWidth > tbl.clientWidth) ? 17 : 0) + "px";
            }
        }

        function mouseUp(e) {
            grips.removeEventListener("mouseup", mouseUp);
            recalcDivs(tbl, grips);
        }

        tbl.onscroll = function () {
            var el = event.target;
            var sel = '#' + el.id + ' > *';
            var els = '#' + el.id;
            $(sel).width($(els).width() + $(els).scrollLeft());

            var grips = document.getElementById(gripsId);
            recalcDivs(tbl, grips);
        };
    }

我要做的就是将z-index设置为高于重叠的div。

尝试添加pointer-events: nonepointer-events: none添加到叠加div的css中,并且所有鼠标事件都将直接从div传递出去,就好像它从未出现过一样。

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

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