如何知道一个div被另一个完全包含

时间:2018-07-17 13:49:43

标签: javascript html css

如何识别一个div完全包含到另一个div中?我有2个div说A和B。当我拖动到A时,我需要知道A完全包含在B内,并且与A没有重叠

2 个答案:

答案 0 :(得分:3)

使用可以将IntersectionObserver用于此任务。

let options = {
  root: document.querySelector('#container'),
  rootMargin: '0px',
};

let callback = entries => {
  entries.forEach(entry => {
    if (entry.intersectionRatio >= 1) {
      console.log("#" + entry.target.id + " is fully inside #container");
    }
    else {
      console.log("#" + entry.target.id + " is NOT fully inside #container");
    }
  });
};

let observer = new IntersectionObserver(callback, options);
observer.observe(document.querySelector('#inner'));
observer.observe(document.querySelector('#outer'));
#container {
  width: 100px;
  height: 100px;
  background: blue;
  position: relative;
}

#inner, #outer {
  width: 50px;
  height: 50px;
  background: green;
  position: absolute;
}

#outer {
  background: red;
  right: -10px;
}
<div id="container">
  <div id="inner"></div>
  <div id="outer"></div>
</div>

答案 1 :(得分:2)

如果我答对了,您可以手动进行:

Plan hash value: 1854531935

--------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                    | Name                    | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                             |                         |     1 |  1595 |       | 35623   (1)| 00:07:08 |
|   1 |  SORT GROUP BY                               |                         |     1 |  1595 |       | 35623   (1)| 00:07:08 |
|*  2 |   FILTER                                     |                         |       |       |       |            |          |
|   3 |    NESTED LOOPS                              |                         |    10 | 15950 |       | 35612   (1)| 00:07:08 |
|   4 |     NESTED LOOPS                             |                         |    10 | 15950 |       | 35612   (1)| 00:07:08 |
|   5 |      NESTED LOOPS                            |                         |    10 | 15720 |       | 35611   (1)| 00:07:08 |
|   6 |       NESTED LOOPS                           |                         |    10 | 15490 |       | 35610   (1)| 00:07:08 |
|   7 |        NESTED LOOPS                          |                         |    10 | 15300 |       | 35609   (1)| 00:07:08 |
|*  8 |         HASH JOIN                            |                         |    10 | 15230 |       | 35608   (1)| 00:07:08 |
|   9 |          NESTED LOOPS                        |                         |     2 |   148 |       |   130   (0)| 00:00:02 |
|  10 |           NESTED LOOPS                       |                         |     2 |   134 |       |   129   (0)| 00:00:02 |
|  11 |            NESTED LOOPS                      |                         |     2 |   100 |       |   128   (0)| 00:00:02 |
|* 12 |             TABLE ACCESS FULL                | STRINGDEFINITION        |     1 |    28 |       |    10   (0)| 00:00:01 |
|* 13 |             TABLE ACCESS BY INDEX ROWID      | STRINGVALUE             |     2 |    44 |       |   118   (0)| 00:00:02 |
|* 14 |              INDEX RANGE SCAN                | STRINGVALUE$COMPOSITE2  |  5780 |       |       |     2   (0)| 00:00:01 |
|* 15 |            TABLE ACCESS BY INDEX ROWID       | WTPART                  |     1 |    17 |       |     1   (0)| 00:00:01 |
|* 16 |             INDEX UNIQUE SCAN                | PK_WTPART               |     1 |       |       |     1   (0)| 00:00:01 |
|* 17 |           INDEX UNIQUE SCAN                  | PK_WTPARTMASTER         |     1 |     7 |       |     1   (0)| 00:00:01 |
|  18 |          VIEW                                |                         |  1062K|  1467M|       | 35476   (1)| 00:07:06 |
|  19 |           UNION-ALL                          |                         |       |       |       |            |          |
|* 20 |            HASH JOIN                         |                         |   898K|   110M|       | 27326   (1)| 00:05:28 |
|  21 |             TABLE ACCESS FULL                | STRINGDEFINITION        |   677 | 18956 |       |    10   (0)| 00:00:01 |
|* 22 |             HASH JOIN                        |                         |   898K|    86M|  7312K| 27314   (1)| 00:05:28 |
|* 23 |              HASH JOIN                       |                         | 82231 |  6343K|  3616K|  3490   (1)| 00:00:42 |
|  24 |               TABLE ACCESS BY INDEX ROWID    | WTPART                  | 82231 |  2650K|       |  2741   (1)| 00:00:33 |
|* 25 |                INDEX SKIP SCAN               | WTPART$COMPOSITE14      | 82231 |       |       |    52   (0)| 00:00:01 |
|  26 |               VIEW                           | index$_join$_004        | 71824 |  3226K|       |   377   (1)| 00:00:05 |
|* 27 |                HASH JOIN                     |                         |       |       |       |            |          |
|  28 |                 INDEX FAST FULL SCAN         | WTPARTMASTER$COMPOSITE3 | 71824 |  3226K|       |    59   (0)| 00:00:01 |
|  29 |                 INDEX FAST FULL SCAN         | WTPARTMASTER$COMPOSITE  | 71824 |  3226K|       |    28   (0)| 00:00:01 |
|  30 |              TABLE ACCESS FULL               | STRINGVALUE             |  3080K|    64M|       | 18503   (1)| 00:03:43 |
|* 31 |            HASH JOIN                         |                         | 80219 |  9714K|       |  4021   (1)| 00:00:49 |
|  32 |             TABLE ACCESS FULL                | UNITDEFINITION          |   365 |  9490 |       |     5   (0)| 00:00:01 |
|* 33 |             HASH JOIN                        |                         |   100K|  9612K|  4072K|  4016   (1)| 00:00:49 |
|  34 |              VIEW                            | index$_join$_011        | 71824 |  3226K|       |   377   (1)| 00:00:05 |
|* 35 |               HASH JOIN                      |                         |       |       |       |            |          |
|  36 |                INDEX FAST FULL SCAN          | WTPARTMASTER$COMPOSITE3 | 71824 |  3226K|       |    59   (0)| 00:00:01 |
|  37 |                INDEX FAST FULL SCAN          | WTPARTMASTER$COMPOSITE  | 71824 |  3226K|       |    28   (0)| 00:00:01 |
|* 38 |              HASH JOIN                       |                         |   100K|  5100K|  3048K|  3137   (1)| 00:00:38 |
|  39 |               INDEX FULL SCAN                | UNITVALUE$COMPOSITE0    |   100K|  1863K|       |    72   (0)| 00:00:01 |
|  40 |               TABLE ACCESS BY INDEX ROWID    | WTPART                  | 82231 |  2650K|       |  2741   (1)| 00:00:33 |
|* 41 |                INDEX SKIP SCAN               | WTPART$COMPOSITE14      | 82231 |       |       |    52   (0)| 00:00:01 |
|* 42 |            HASH JOIN                         |                         | 82231 |  9716K|       |  3973   (1)| 00:00:48 |
|  43 |             TABLE ACCESS FULL                | BOOLEANDEFINITION       |    31 |   775 |       |     4   (0)| 00:00:01 |
|* 44 |             HASH JOIN                        |                         | 82231 |  7709K|  4072K|  3969   (1)| 00:00:48 |
|  45 |              VIEW                            | index$_join$_032        | 71824 |  3226K|       |   377   (1)| 00:00:05 |
|* 46 |               HASH JOIN                      |                         |       |       |       |            |          |
|  47 |                INDEX FAST FULL SCAN          | WTPARTMASTER$COMPOSITE3 | 71824 |  3226K|       |    59   (0)| 00:00:01 |
|  48 |                INDEX FAST FULL SCAN          | WTPARTMASTER$COMPOSITE  | 71824 |  3226K|       |    28   (0)| 00:00:01 |
|* 49 |              HASH JOIN                       |                         | 82231 |  4015K|  3616K|  3153   (1)| 00:00:38 |
|  50 |               TABLE ACCESS BY INDEX ROWID    | WTPART                  | 82231 |  2650K|       |  2741   (1)| 00:00:33 |
|* 51 |                INDEX SKIP SCAN               | WTPART$COMPOSITE14      | 82231 |       |       |    52   (0)| 00:00:01 |
|  52 |               INDEX FULL SCAN                | BOOLEANVALUE$COMPOSITE0 |   139K|  2315K|       |    44   (0)| 00:00:01 |
|  53 |            NESTED LOOPS                      |                         |   749 |  1078K|       |   155   (1)| 00:00:02 |
|  54 |             NESTED LOOPS                     |                         |   749 |  1078K|       |   155   (1)| 00:00:02 |
|  55 |              VIEW                            | VW_JF_SET$368F68B3      |   749 |  1045K|       |    81   (2)| 00:00:01 |
|  56 |               UNION-ALL                      |                         |       |       |       |            |          |
|  57 |                NESTED LOOPS                  |                         |   745 | 55130 |       |    78   (2)| 00:00:01 |
|  58 |                 NESTED LOOPS                 |                         |   745 | 55130 |       |    78   (2)| 00:00:01 |
|  59 |                  MERGE JOIN                  |                         |   745 | 30545 |       |     3  (34)| 00:00:01 |
|  60 |                   TABLE ACCESS BY INDEX ROWID| FLOATDEFINITION         |    41 |   984 |       |     1   (0)| 00:00:01 |
|  61 |                    INDEX FULL SCAN           | PK_FLOATDEFINITION      |    41 |       |       |     1   (0)| 00:00:01 |
|* 62 |                   SORT JOIN                  |                         |   756 | 12852 |       |     2  (50)| 00:00:01 |
|  63 |                    INDEX FULL SCAN           | FLOATVALUE$COMPOSITE0   |   756 | 12852 |       |     1   (0)| 00:00:01 |
|* 64 |                  INDEX UNIQUE SCAN           | PK_WTPART               |     1 |       |       |     1   (0)| 00:00:01 |
|* 65 |                 TABLE ACCESS BY INDEX ROWID  | WTPART                  |     1 |    33 |       |     1   (0)| 00:00:01 |
|  66 |                NESTED LOOPS                  |                         |     4 |   328 |       |     3   (0)| 00:00:01 |
|  67 |                 NESTED LOOPS                 |                         |     4 |   328 |       |     3   (0)| 00:00:01 |
|  68 |                  NESTED LOOPS                |                         |     4 |   196 |       |     2   (0)| 00:00:01 |
|  69 |                   INDEX FULL SCAN            | INTEGERVALUE$COMPOSITE0 |     4 |    68 |       |     1   (0)| 00:00:01 |
|  70 |                   TABLE ACCESS BY INDEX ROWID| INTEGERDEFINITION       |     1 |    32 |       |     1   (0)| 00:00:01 |
|* 71 |                    INDEX UNIQUE SCAN         | PK_INTEGERDEFINITION    |     1 |       |       |     1   (0)| 00:00:01 |
|* 72 |                  INDEX UNIQUE SCAN           | PK_WTPART               |     1 |       |       |     1   (0)| 00:00:01 |
|* 73 |                 TABLE ACCESS BY INDEX ROWID  | WTPART                  |     1 |    33 |       |     1   (0)| 00:00:01 |
|* 74 |              INDEX UNIQUE SCAN               | PK_WTPARTMASTER         |     1 |       |       |     1   (0)| 00:00:01 |
|  75 |             TABLE ACCESS BY INDEX ROWID      | WTPARTMASTER            |     1 |    46 |       |     1   (0)| 00:00:01 |
|* 76 |         INDEX UNIQUE SCAN                    | PK_WTPARTMASTER         |     1 |     7 |       |     1   (0)| 00:00:01 |
|  77 |        TABLE ACCESS BY INDEX ROWID           | WTPART                  |     1 |    19 |       |     1   (0)| 00:00:01 |
|* 78 |         INDEX UNIQUE SCAN                    | PK_WTPART               |     1 |       |       |     1   (0)| 00:00:01 |
|  79 |       TABLE ACCESS BY INDEX ROWID            | WTUSER                  |     1 |    23 |       |     1   (0)| 00:00:01 |
|* 80 |        INDEX UNIQUE SCAN                     | PK_WTUSER               |     1 |       |       |     1   (0)| 00:00:01 |
|* 81 |      INDEX UNIQUE SCAN                       | PK_WTUSER               |     1 |       |       |     1   (0)| 00:00:01 |
|  82 |     TABLE ACCESS BY INDEX ROWID              | WTUSER                  |     1 |    23 |       |     1   (0)| 00:00:01 |
|  83 |    SORT AGGREGATE                            |                         |     1 |    17 |       |            |          |
|  84 |     NESTED LOOPS                             |                         |     4 |    68 |       |     2   (0)| 00:00:01 |
|* 85 |      INDEX UNIQUE SCAN                       | PK_WTPARTMASTER         |     1 |     7 |       |     1   (0)| 00:00:01 |
|  86 |      FIRST ROW                               |                         |     4 |    40 |       |     1   (0)| 00:00:01 |
|* 87 |       INDEX RANGE SCAN (MIN/MAX)             | WTPART$UNIQUE50         |     4 |    40 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("A1"."LAST_REVISION"= (SELECT MAX("P3"."VERSIONIDA2VERSIONINFO") FROM "WC"."WTPARTMASTER" 
          "PM3","WC"."WTPART" "P3" WHERE "P3"."IDA3MASTERREFERENCE"=:B1 AND "PM3"."IDA2A2"=:B2))
   8 - access("P"."IDA2A2"="A1"."PARTVERSION_ID")
  12 - filter("SD"."DISPLAYNAME"='Part Classification')
  13 - filter(CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040356' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040354' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040357' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040358' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040359' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040361' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040355' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040367' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040363' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040365' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040366' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040360' OR CAST("SV"."VALUE2" AS VARCHAR2(1500))='ABBclass040362' OR CAST("SV"."VALUE2" AS 
          VARCHAR2(1500))='ABBclass040364')
  14 - access("SV"."IDA3A6"="SD"."IDA2A2")
  15 - filter("P"."LATESTITERATIONINFO"=1)
  16 - access("SV"."IDA3A4"="P"."IDA2A2")
  17 - access("P"."IDA3MASTERREFERENCE"="PM"."IDA2A2")
  20 - access("SV"."IDA3A6"="SD"."IDA2A2")
  22 - access("SV"."IDA3A4"="P"."IDA2A2")
  23 - access("P"."IDA3MASTERREFERENCE"="PM"."IDA2A2")
  25 - access("P"."LATESTITERATIONINFO"=1)
   filter("P"."LATESTITERATIONINFO"=1)
  27 - access(ROWID=ROWID)
  31 - access("UV"."IDA3A6"="UD"."IDA2A2")
  33 - access("P"."IDA3MASTERREFERENCE"="PM"."IDA2A2")
  35 - access(ROWID=ROWID)
  38 - access("UV"."IDA3A4"="P"."IDA2A2")
  41 - access("P"."LATESTITERATIONINFO"=1)
   filter("P"."LATESTITERATIONINFO"=1)
  42 - access("BV"."IDA3A6"="BD"."IDA2A2")
  44 - access("P"."IDA3MASTERREFERENCE"="PM"."IDA2A2")
  46 - access(ROWID=ROWID)
  49 - access("BV"."IDA3A4"="P"."IDA2A2")
  51 - access("P"."LATESTITERATIONINFO"=1)
   filter("P"."LATESTITERATIONINFO"=1)
  62 - access("FV"."IDA3A6"="FD"."IDA2A2")
   filter("FV"."IDA3A6"="FD"."IDA2A2")
  64 - access("FV"."IDA3A4"="P"."IDA2A2")
  65 - filter("P"."LATESTITERATIONINFO"=1)
  71 - access("IV"."IDA3A6"="ID"."IDA2A2")
  72 - access("IV"."IDA3A4"="P"."IDA2A2")
  73 - filter("P"."LATESTITERATIONINFO"=1)
  74 - access("ITEM_1"="PM"."IDA2A2")
  76 - access("A1"."PART_ID"="PM1"."IDA2A2")
  78 - access("A1"."PARTVERSION_ID"="P2"."IDA2A2")
  80 - access("P2"."IDA3D2ITERATIONINFO"="U"."IDA2A2")
  81 - access("P2"."IDA3B2ITERATIONINFO"="U2"."IDA2A2")
  85 - access("PM3"."IDA2A2"=:B1)
  87 - access("P3"."IDA3MASTERREFERENCE"=:B1)