{"id":3372,"date":"2024-11-10T09:48:37","date_gmt":"2024-11-10T01:48:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3372\/"},"modified":"2024-11-10T09:48:37","modified_gmt":"2024-11-10T01:48:37","slug":"js%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e6%a8%aa%e5%90%91%e6%bb%9a%e5%8a%a8%e6%9d%a1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3372\/","title":{"rendered":"js\u5982\u4f55\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761"},"content":{"rendered":"<blockquote><p>\n  javascript\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761\u7684\u65b9\u5f0f\u6709\uff1a\u901a\u8fc7\u8bbe\u7f6e css \u5c5e\u6027 overflow-x: scroll;\u4f7f\u7528 javascript api \u521b\u5efa\u548c\u7ba1\u7406\u6eda\u52a8\u6761\uff1b\u501f\u52a9 jquery \u63d2\u4ef6\uff0c\u5982 jscrollpane\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110811003589100.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761\u63d2\u56fe\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761\u63d2\u56fe\" \/><\/p>\n<h2>JavaScript\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761<\/h2>\n<p><strong>\u5b9e\u73b0\u65b9\u5f0f\uff1a<\/strong><\/p>\n<p><strong>1. CSS \u5c5e\u6027<\/strong><\/p>\n<pre>overflow-x: scroll;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06\u6b64 CSS \u5c5e\u6027\u5e94\u7528\u4e8e\u67d0\u4e2a\u5143\u7d20\uff0c\u4f7f\u5176\u6c34\u5e73\u65b9\u5411\u51fa\u73b0\u6eda\u52a8\u6761\u3002<\/p>\n<p><strong>2. JavaScript API<\/strong><\/p>\n<p>\u4f7f\u7528 JavaScript API \u53ef\u4ee5\u52a8\u6001\u5730\u521b\u5efa\u548c\u7ba1\u7406\u6eda\u52a8\u6761\uff1a<\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6c34\u5e73\u6eda\u52a8\u6761\nconst scrollbar = document.createElement('div');\nscrollbar.style.overflowX = 'scroll';\n\n\/\/ \u5c06\u6eda\u52a8\u6761\u6dfb\u52a0\u5230\u6587\u6863\u4e2d\ndocument.body.appendChild(scrollbar);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. jQuery \u63d2\u4ef6<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 jQuery \u63d2\u4ef6\uff0c\u5982 jScrollPane\uff0c\u8f7b\u677e\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\uff1a<\/p>\n<pre>\/\/ \u4f7f\u7528 jScrollPane \u63d2\u4ef6\u521b\u5efa\u6eda\u52a8\u6761\n$('.my-container').jScrollPane({horizontalGutter: 10});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u4e3a\u9700\u8981\u6a2a\u5411\u6eda\u52a8\u7684\u5143\u7d20\u8bbe\u7f6e -x: scroll; \u5c5e\u6027\u3002<\/li>\n<li>\u5bf9\u4e8e\u54cd\u5e94\u5f0f\u8bbe\u8ba1\uff0c\u53ef\u4ee5\u5728\u7a97\u53e3\u5927\u5c0f\u53d1\u751f\u53d8\u5316\u65f6\u4f7f\u7528 JavaScript \u6216 CSS \u5a92\u4f53\u67e5\u8be2\u52a8\u6001\u6dfb\u52a0\u6216\u79fb\u9664\u6eda\u52a8\u6761\u3002<\/li>\n<li>\u4f7f\u7528 JavaScript API \u53ef\u4ee5\u521b\u5efa\u81ea\u5b9a\u4e49\u6eda\u52a8\u6761\uff0c\u5e76\u63a7\u5236\u5176\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<p><strong>\u4f18\u52bf\uff1a<\/strong><\/p>\n<ul>\n<li>\u5141\u8bb8\u5728\u6c34\u5e73\u65b9\u5411\u4e0a\u6eda\u52a8\u5185\u5bb9\uff0c\u5373\u4f7f\u5185\u5bb9\u8d85\u51fa\u5c4f\u5e55\u5bbd\u5ea6\u3002<\/li>\n<li>\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\uff0c\u5c24\u5176\u662f\u5728\u5bbd\u5c4f\u5e55\u8bbe\u5907\u4e0a\u6d4f\u89c8\u6c34\u5e73\u5217\u8868\u6216\u8868\u683c\u65f6\u3002<\/li>\n<li>\u5141\u8bb8\u5728\u4e00\u4e2a\u7a97\u53e3\u4e2d\u663e\u793a\u66f4\u591a\u5185\u5bb9\uff0c\u4ece\u800c\u63d0\u9ad8\u53ef\u7528\u7a7a\u95f4\u5229\u7528\u7387\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761\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>javascript\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761\u7684\u65b9\u5f0f\u6709\uff1a\u901a\u8fc7\u8bbe\u7f6e css \u5c5e\u6027 overflow-x: scroll;\u4f7f\u7528 javascript api \u521b\u5efa\u548c\u7ba1\u7406\u6eda\u52a8\u6761\uff1b\u501f\u52a9 jquery \u63d2\u4ef6\uff0c\u5982 jscrollpane\u3002 JavaScript\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\u6761 \u5b9e\u73b0\u65b9\u5f0f\uff1a 1. CSS \u5c5e\u6027 overflow-x: scroll; \u767b\u5f55\u540e\u590d\u5236 \u5c06\u6b64 CSS \u5c5e\u6027\u5e94\u7528\u4e8e\u67d0\u4e2a\u5143\u7d20\uff0c\u4f7f\u5176\u6c34\u5e73\u65b9\u5411\u51fa\u73b0\u6eda\u52a8\u6761\u3002 2. JavaScript API \u4f7f\u7528 JavaScript API \u53ef\u4ee5\u52a8\u6001\u5730\u521b\u5efa\u548c\u7ba1\u7406\u6eda\u52a8\u6761\uff1a \/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6c34\u5e73\u6eda\u52a8\u6761 const scrollbar = document.createElement(&#8216;div&#8217;); scrollbar.style.overflowX = &#8216;scroll&#8217;; \/\/ \u5c06\u6eda\u52a8\u6761\u6dfb\u52a0\u5230\u6587\u6863\u4e2d document.body.appendChild(scrollbar); \u767b\u5f55\u540e\u590d\u5236 3. jQuery \u63d2\u4ef6 \u53ef\u4ee5\u4f7f\u7528 jQuery \u63d2\u4ef6\uff0c\u5982 jScrollPane\uff0c\u8f7b\u677e\u5b9e\u73b0\u6a2a\u5411\u6eda\u52a8\uff1a \/\/ \u4f7f\u7528 jScrollPane \u63d2\u4ef6\u521b\u5efa\u6eda\u52a8\u6761 $(&#8216;.my-container&#8217;).jScrollPane({horizontalGutter: 10}); [&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-3372","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3372","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=3372"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3372\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}