{"id":3282,"date":"2024-11-10T15:38:56","date_gmt":"2024-11-10T07:38:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3282\/"},"modified":"2024-11-10T15:38:56","modified_gmt":"2024-11-10T07:38:56","slug":"js%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e8%bd%ae%e6%92%ad","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3282\/","title":{"rendered":"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad"},"content":{"rendered":"<blockquote><p>\n  \u8f6e\u64ad\u662f\u4e00\u79cd\u81ea\u52a8\u5faa\u73af\u64ad\u653e\u56fe\u50cf\u6216\u5185\u5bb9\u7684\u4ea4\u4e92\u5f0f\u6548\u679c\u3002javascript \u5b9e\u73b0\u8f6e\u64ad\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa html \u5bb9\u5668\u548c\u56fe\u50cf\u6807\u8bb0\u3002\u4f7f\u7528 css \u8bbe\u7f6e\u6837\u5f0f\u3002\u5b9a\u4e49 javascript \u53d8\u91cf\u548c\u5e38\u91cf\u3002\u521b\u5efa\u5b9a\u65f6\u5668\u51fd\u6570\u81ea\u52a8\u5207\u6362\u56fe\u50cf\u3002\u5c55\u793a\u5f53\u524d\u7d22\u5f15\u5904\u7684\u5e7b\u706f\u7247\u3002\u6bcf\u9694\u6307\u5b9a\u65f6\u95f4\u95f4\u9694\u8c03\u7528 slidenext \u51fd\u6570\u542f\u52a8\u8f6e\u64ad\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809002115083.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe\" \/><\/p>\n<p><strong>JS \u8f6e\u64ad\u5b9e\u73b0<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u8f6e\u64ad\uff1f<\/strong><\/p>\n<p>\u8f6e\u64ad\u662f\u4e00\u79cd\u52a8\u6001\u5c55\u793a\u56fe\u50cf\u6216\u5185\u5bb9\u7684\u4ea4\u4e92\u5f0f\u6548\u679c\uff0c\u5b83\u4f1a\u81ea\u52a8\u5faa\u73af\u64ad\u653e\u4e00\u7ec4\u56fe\u50cf\u6216\u5185\u5bb9\u3002<\/p>\n<p><strong>JavaScript \u5b9e\u73b0\u8f6e\u64ad<\/strong><\/p>\n<p><strong>1. HTML \u6807\u8bb0<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u5728 HTML \u4e2d\u521b\u5efa\u8f6e\u64ad\u5bb9\u5668\u5e76\u4e3a\u56fe\u50cf\u6216\u5185\u5bb9\u6dfb\u52a0\u6807\u8bb0\u3002<\/p>\n<pre>&lt;div id=\"carousel\"&gt;\n  @@##@@\n  @@##@@\n  @@##@@\n&lt;\/div&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. CSS \u6837\u5f0f<\/strong><\/p>\n<p>\u4f7f\u7528 CSS \u8bbe\u7f6e\u8f6e\u64ad\u5bb9\u5668\u548c\u56fe\u50cf\u7684\u6837\u5f0f\uff0c\u5305\u62ec\u5bbd\u9ad8\u3001\u4f4d\u7f6e\u548c\u8fc7\u6e21\u6548\u679c\u3002<\/p>\n<pre>#carousel {\n  width: 500px;\n  height: 300px;\n  overflow: hidden;\n}\n\n#carousel img {\n  width: 100%;\n  height: 100%;\n  transition: transform 0.5s ease-in-out;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. JavaScript \u4ee3\u7801<\/strong><\/p>\n<p><strong>\u53d8\u91cf\u548c\u5e38\u91cf<\/strong><\/p>\n<p>\u5b9a\u4e49\u53d8\u91cf\u548c\u5e38\u91cf\uff0c\u5305\u62ec\u8f6e\u64ad\u5bb9\u5668\u3001\u56fe\u50cf\u6570\u7ec4\u3001\u5f53\u524d\u7d22\u5f15\u548c\u52a8\u753b\u6301\u7eed\u65f6\u95f4\u3002<\/p>\n<pre>const carousel = document.getElementById('carousel');\nconst images = carousel.querySelectorAll('img');\nlet currentIndex = 0;\nconst animationDuration = 500;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5b9a\u65f6\u5668\u51fd\u6570<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u5b9a\u65f6\u5668\u51fd\u6570\uff0c\u6bcf\u9694\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u81ea\u52a8\u5207\u6362\u56fe\u50cf\u3002<\/p>\n<pre>function slideNext() {\n  currentIndex++;\n  if (currentIndex &gt;= images.length) {\n    currentIndex = 0;\n  }\n  showSlide(currentIndex);\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5c55\u793a\u5e7b\u706f\u7247\u51fd\u6570<\/strong><\/p>\n<p>\u5c55\u793a\u5f53\u524d\u7d22\u5f15\u5904\u7684\u5e7b\u706f\u7247\uff0c\u5e76\u6dfb\u52a0\u8fc7\u6e21\u52a8\u753b\u3002<\/p>\n<pre>function showSlide(index) {\n  for (let i = 0; i &lt; images.length; i++) {\n    images[i].style.transform = `translateX(-${index * 100}%)`;\n  }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u542f\u52a8\u8f6e\u64ad<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u542f\u52a8\u8f6e\u64ad\uff0c\u6bcf\u9694\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u8c03\u7528 slideNext \u51fd\u6570\u3002<\/p>\n<pre>setInterval(slideNext, 3000);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a JavaScript \u4ee3\u7801\u5c06\u5728\u8f6e\u64ad\u5bb9\u5668\u4e2d\u81ea\u52a8\u5faa\u73af\u64ad\u653e\u4e00\u7ec4\u56fe\u50cf\uff0c\u6bcf\u9694 3 \u79d2\u5207\u6362\u4e00\u6b21\u56fe\u50cf\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.php.cn\/faq\/image1.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe1\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe1\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.php.cn\/faq\/image2.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe2\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe2\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.php.cn\/faq\/image3.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe3\" alt=\"js\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\u63d2\u56fe3\" \/> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u5b9e\u73b0\u8f6e\u64ad\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>\u8f6e\u64ad\u662f\u4e00\u79cd\u81ea\u52a8\u5faa\u73af\u64ad\u653e\u56fe\u50cf\u6216\u5185\u5bb9\u7684\u4ea4\u4e92\u5f0f\u6548\u679c\u3002javascript \u5b9e\u73b0\u8f6e\u64ad\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa html \u5bb9\u5668\u548c\u56fe\u50cf\u6807\u8bb0\u3002\u4f7f\u7528 css \u8bbe\u7f6e\u6837\u5f0f\u3002\u5b9a\u4e49 javascript \u53d8\u91cf\u548c\u5e38\u91cf\u3002\u521b\u5efa\u5b9a\u65f6\u5668\u51fd\u6570\u81ea\u52a8\u5207\u6362\u56fe\u50cf\u3002\u5c55\u793a\u5f53\u524d\u7d22\u5f15\u5904\u7684\u5e7b\u706f\u7247\u3002\u6bcf\u9694\u6307\u5b9a\u65f6\u95f4\u95f4\u9694\u8c03\u7528 slidenext \u51fd\u6570\u542f\u52a8\u8f6e\u64ad\u3002 JS \u8f6e\u64ad\u5b9e\u73b0 \u4ec0\u4e48\u662f\u8f6e\u64ad\uff1f \u8f6e\u64ad\u662f\u4e00\u79cd\u52a8\u6001\u5c55\u793a\u56fe\u50cf\u6216\u5185\u5bb9\u7684\u4ea4\u4e92\u5f0f\u6548\u679c\uff0c\u5b83\u4f1a\u81ea\u52a8\u5faa\u73af\u64ad\u653e\u4e00\u7ec4\u56fe\u50cf\u6216\u5185\u5bb9\u3002 JavaScript \u5b9e\u73b0\u8f6e\u64ad 1. HTML \u6807\u8bb0 \u9996\u5148\uff0c\u5728 HTML \u4e2d\u521b\u5efa\u8f6e\u64ad\u5bb9\u5668\u5e76\u4e3a\u56fe\u50cf\u6216\u5185\u5bb9\u6dfb\u52a0\u6807\u8bb0\u3002 &lt;div id=&#8221;carousel&#8221;&gt; @@##@@ @@##@@ @@##@@ &lt;\/div&gt; \u767b\u5f55\u540e\u590d\u5236 2. CSS \u6837\u5f0f \u4f7f\u7528 CSS \u8bbe\u7f6e\u8f6e\u64ad\u5bb9\u5668\u548c\u56fe\u50cf\u7684\u6837\u5f0f\uff0c\u5305\u62ec\u5bbd\u9ad8\u3001\u4f4d\u7f6e\u548c\u8fc7\u6e21\u6548\u679c\u3002 #carousel { width: 500px; height: 300px; overflow: hidden; } #carousel img { width: 100%; height: 100%; transition: transform 0.5s ease-in-out; [&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-3282","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3282","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=3282"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3282\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}