index.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. font-size: 0
  13. }
  14. .i {
  15. width: 200px;
  16. height: 200px;
  17. /* border: 1px solid orangered; */
  18. background-color: #000;
  19. /* float: left; */
  20. margin: 0;
  21. border: 0
  22. }
  23. .div {
  24. margin: 200px;
  25. width: 200px;
  26. padding: 100px;
  27. border: 1px solid black;
  28. position: relative;
  29. }
  30. .div2 {
  31. margin: 200px;
  32. width: 200px;
  33. padding: 100px;
  34. border: 1px solid black;
  35. float: left;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <img src="./1_answer_a.png" alt="" class="i">
  41. <div class="div2">
  42. <div class="div">
  43. <div class="div">
  44. <img src="./1_answer_b.png" alt="" class="i" onclick="drag()">
  45. </div>
  46. </div>
  47. </div>
  48. <div class="div2">
  49. <div class="div2">
  50. <div class="div2">
  51. <img src="./1_answer_b.png" alt="" class="i" onclick="drag()">
  52. </div>
  53. </div>
  54. </div>
  55. </body>
  56. <script>
  57. function drag(e) {
  58. e = e || window.event;
  59. console.log(e.target);
  60. console.log(e.target.offsetLeft);
  61. console.log(getOffsetLeft(e.target));
  62. }
  63. function getOffsetLeft(obj) {
  64. let tmp = obj.offsetLeft;
  65. let val = obj.offsetParent;
  66. while (val != null) {
  67. tmp += val.offsetLeft;
  68. val = val.offsetParent;
  69. }
  70. return tmp;
  71. };
  72. let arr = [
  73. [0, 1, 1],
  74. [1, 1, 0],
  75. [1, 0, 0]
  76. ]
  77. [
  78. [1, null, null],
  79. [0, 0, 1],
  80. [1, null, null]
  81. ]
  82. [
  83. [1, 0, 1],
  84. [1, 0, 1],
  85. [0, 1, 0]
  86. ]
  87. function isOk(arr) {
  88. let total = 0
  89. for (var i = 0; i < arr.length; i++) {
  90. // if(){
  91. // }
  92. total += i;
  93. }
  94. console.log(i)
  95. }
  96. </script>
  97. </html>