{"id":27580,"date":"2024-11-24T08:33:05","date_gmt":"2024-11-24T00:33:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27580\/"},"modified":"2024-11-24T08:33:05","modified_gmt":"2024-11-24T00:33:05","slug":"react-%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%ba%e5%8a%a8%e6%80%81%e5%88%9b%e5%bb%ba%e7%9a%84-div-%e6%b7%bb%e5%8a%a0%e8%a1%8c%e5%8f%b7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27580\/","title":{"rendered":"React \u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173129296234293.jpg\" class=\"aligncenter\" title=\"React \u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" alt=\"React \u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 react div \u6dfb\u52a0\u884c\u53f7\uff1f<\/strong><\/p>\n<p>\u5728 react \u7ec4\u4ef6\u4e2d\uff0c\u5faa\u73af\u521b\u5efa\u591a\u4e2a\u5143\u7d20\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u6dfb\u52a0\u884c\u53f7\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u521b\u5efa\u7d22\u5f15\u6570\u7ec4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u4e0e\u53ef\u5faa\u73af\u6570\u636e\u9879\u6570\u76ee\u76f8\u7b49\u7684\u7d22\u5f15\u6570\u7ec4\u3002<\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u4f7f\u7528\u521b\u5efa\u884c\u53f7<\/strong><\/p>\n<p>\u9488\u5bf9\u7d22\u5f15\u6570\u7ec4\u521b\u5efa\u7684 div \u5143\u7d20\u8bbe\u7f6e\u7edd\u5bf9\u5b9a\u4f4d\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728\u5bb9\u5668 div \u7684\u5de6\u4fa7\u3002<\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u4f7f\u7528\u521b\u5efa\u65b9\u5757<\/strong><\/p>\n<p>\u5bf9\u4e8e\u53ef\u5faa\u73af\u7684\u6570\u636e\u9879\u521b\u5efa\u7684 div \u5143\u7d20\uff0c\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\uff0c\u4f7f\u5176\u76f8\u5bf9\u4e8e\u5bb9\u5668 div \u8fdb\u884c\u5b9a\u4f4d\u3002<\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u9690\u85cf\u6ea2\u51fa\u90e8\u5206<\/strong><\/p>\n<p>\u5c06\u5bb9\u5668 div \u7684  \u5c5e\u6027\u8bbe\u7f6e\u4e3a hidden\uff0c\u4ee5\u786e\u4fdd\u884c\u53f7\u548c\u65b9\u5757\u4fdd\u6301\u5728\u6307\u5b9a\u533a\u57df\u5185\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>const itemdata = new array(500).fill(0);\nconst indexdata = new array(20).fill(0);\n\nreturn (\n  &lt;div classname=\"app\"&gt;\n    &lt;div classname=\"left-box\"&gt;\n      {indexdata.map((item, index) =&gt; (\n        &lt;div key={index} style={{ fontsize: \"9px\", width: \"19px\", height: \"20px\", margin: \"2px\" }}&gt;{index}&lt;\/div&gt;\n      ))}\n    &lt;\/div&gt;\n    &lt;div classname=\"right-box\"&gt;\n      {itemdata.map((item, index) =&gt; (\n        &lt;div key={index} style={{ display: \"inline-block\", width: \"9px\", height: \"9px\", margin: \"2px\", backgroundcolor: item.selected ? \"green\" : \"lightgreen\" }}&gt;&lt;\/div&gt;\n      ))}\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6837\u5f0f\u8868\uff1a<\/strong><\/p>\n<pre>.App {\n  overflow: hidden;\n  position: relative;\n}\n\n.left-box {\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: 19px;\n  overflow: hidden;\n}\n\n.right-box {\n  margin-left: 19px;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u884c\u53f7\u7684\u65b9\u5757\u7f51\u683c\u3002\u884c\u53f7\u4f4d\u4e8e\u5de6\u4fa7\uff0c\u800c\u65b9\u5757\u4f4d\u4e8e\u53f3\u4fa7\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fReact \u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 div \u6dfb\u52a0\u884c\u53f7\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4e3a\u52a8\u6001\u521b\u5efa\u7684 react div \u6dfb\u52a0\u884c\u53f7\uff1f \u5728 react \u7ec4\u4ef6\u4e2d\uff0c\u5faa\u73af\u521b\u5efa\u591a\u4e2a\u5143\u7d20\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u6dfb\u52a0\u884c\u53f7\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u6b65\u9aa4 1\uff1a\u521b\u5efa\u7d22\u5f15\u6570\u7ec4 \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u4e0e\u53ef\u5faa\u73af\u6570\u636e\u9879\u6570\u76ee\u76f8\u7b49\u7684\u7d22\u5f15\u6570\u7ec4\u3002 \u6b65\u9aa4 2\uff1a\u4f7f\u7528\u521b\u5efa\u884c\u53f7 \u9488\u5bf9\u7d22\u5f15\u6570\u7ec4\u521b\u5efa\u7684 div \u5143\u7d20\u8bbe\u7f6e\u7edd\u5bf9\u5b9a\u4f4d\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728\u5bb9\u5668 div \u7684\u5de6\u4fa7\u3002 \u6b65\u9aa4 3\uff1a\u4f7f\u7528\u521b\u5efa\u65b9\u5757 \u5bf9\u4e8e\u53ef\u5faa\u73af\u7684\u6570\u636e\u9879\u521b\u5efa\u7684 div \u5143\u7d20\uff0c\u8bbe\u7f6e\u76f8\u5bf9\u5b9a\u4f4d\uff0c\u4f7f\u5176\u76f8\u5bf9\u4e8e\u5bb9\u5668 div \u8fdb\u884c\u5b9a\u4f4d\u3002 \u6b65\u9aa4 4\uff1a\u9690\u85cf\u6ea2\u51fa\u90e8\u5206 \u5c06\u5bb9\u5668 div \u7684 \u5c5e\u6027\u8bbe\u7f6e\u4e3a hidden\uff0c\u4ee5\u786e\u4fdd\u884c\u53f7\u548c\u65b9\u5757\u4fdd\u6301\u5728\u6307\u5b9a\u533a\u57df\u5185\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a const itemdata = new array(500).fill(0); const indexdata = new array(20).fill(0); return ( &lt;div classname=&#8221;app&#8221;&gt; &lt;div classname=&#8221;left-box&#8221;&gt; {indexdata.map((item, index) =&gt; ( &lt;div key={index} [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27580","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27580"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27580\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}