{"id":219,"date":"2025-12-01T21:03:59","date_gmt":"2025-12-01T13:03:59","guid":{"rendered":"https:\/\/caoxunyi.cn\/?p=219"},"modified":"2025-12-01T21:03:59","modified_gmt":"2025-12-01T13:03:59","slug":"web%e5%a4%a7%e4%bd%9c%e4%b8%9a%e8%b8%a9%e5%9d%91%e6%97%a5%e8%ae%b0%ef%bc%9a%e5%a6%82%e4%bd%95%e8%ae%a9%e7%bd%91%e9%a1%b5%e5%88%87%e6%8d%a2%e6%97%b6%e9%9f%b3%e4%b9%90%e4%b8%8d%e5%81%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/caoxunyi.cn\/index.php\/219\/","title":{"rendered":"Web\u5927\u4f5c\u4e1a\u8e29\u5751\u65e5\u8bb0\uff1a\u5982\u4f55\u8ba9\u7f51\u9875\u5207\u6362\u65f6\u97f3\u4e50\u4e0d\u505c\uff1f"},"content":{"rendered":"<blockquote>\n<p><strong>\u524d\u8a00<\/strong>\n\u6700\u8fd1\u5728\u6413\u6211\u7684 Web \u671f\u672b\u5927\u4f5c\u4e1a\u2014\u2014\u4e00\u4e2a\u521d\u97f3\u672a\u6765\uff08Miku\uff09\u4e3b\u9898\u7684\u753b\u5eca\u7f51\u7ad9\u3002\u9875\u9762\u505a\u5f97\u5f88\u6f02\u4eae\uff0c\u4f46\u603b\u89c9\u5f97\u5c11\u4e86\u70b9\u7075\u9b42\u2026\u2026\u6ca1\u9519\uff0c\u662f BGM\uff01\n\u672c\u4ee5\u4e3a\u52a0\u4e2a\u64ad\u653e\u5668\u5f88\u7b80\u5355\uff0c\u7ed3\u679c\u6ca1\u60f3\u5230\u4e3a\u4e86\u5b9e\u73b0\u201c\u5207\u6362\u9875\u9762\u97f3\u4e50\u4e0d\u65ad\u201d\uff0c\u6211\u628a\u6574\u4e2a\u7f51\u7ad9\u7684\u67b6\u6784\u90fd\u91cd\u6784\u4e86\u4e00\u904d\u3002\u4eca\u5929\u5c31\u6765\u5206\u4eab\u4e00\u4e0b\u8fd9\u4e2a\u4ece APlayer \u5230 iframe \u67b6\u6784\u7684\u8fdb\u5316\u8fc7\u7a0b\u3002<\/p>\n<\/blockquote>\n<h2>\u7b2c\u4e00\u9636\u6bb5\uff1a\u521d\u89c1 APlayer<\/h2>\n<p>\u4e3a\u4e86\u7ed9\u6211\u7684\u201cMiku \u753b\u5eca\u201d\u52a0\u4e0a\u97f3\u4e50\uff0c\u6211\u9009\u4e2d\u4e86\u989c\u503c\u8d85\u9ad8\u7684\u5f00\u6e90\u64ad\u653e\u5668 <strong>APlayer<\/strong>\u3002<\/p>\n<h3>1. \u5f15\u5165\u64ad\u653e\u5668<\/h3>\n<p>\u8fd9\u4e2a\u6b65\u9aa4\u5f88\u7b80\u5355\uff0c\u4e0d\u7528 npm\uff0c\u76f4\u63a5\u7528 CDN \u5f15\u5165 CSS \u548c JS \u5c31\u80fd\u7528\uff0c\u975e\u5e38\u9002\u5408\u6211\u4eec\u8fd9\u79cd\u4ea4\u4f5c\u4e1a\u7684\u9759\u6001\u9875\u9762\u9879\u76ee\u3002<\/p>\n<pre><code class=\"lang-html language-html html\">&lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/cdn.jsdelivr.net\/npm\/aplayer\/dist\/APlayer.min.css&quot;&gt;\n&lt;script src=&quot;https:\/\/cdn.jsdelivr.net\/npm\/aplayer\/dist\/APlayer.min.js&quot;&gt;&lt;\/script&gt;<\/code><\/pre>\n<h3>2. \u521d\u59cb\u5316<\/h3>\n<p>\u6211\u5728\u9875\u9762\u5e95\u90e8\u52a0\u4e86\u4e00\u4e2a <code>&lt;div id=&quot;aplayer&quot;&gt;&lt;\/div&gt;<\/code>\uff0c\u7136\u540e\u5199\u4e86\u6bb5 JS\uff1a<\/p>\n<pre><code class=\"lang-javascript language-javascript javascript\">const ap = new APlayer({\n    container: document.getElementById('aplayer'),\n    fixed: true,          \/\/ \u5f00\u542f\u5438\u5e95\u6a21\u5f0f\uff0c\u8ba9\u5b83\u4e00\u76f4\u60ac\u6d6e\u5728\u5de6\u4e0b\u89d2\n    theme: '#39c5bb',     \/\/ Miku\u4e13\u5c5e\u7684\u8471\u7eff\u8272\uff01\n    audio: [\n        {\n            name: 'World is Mine',\n            artist: 'Hatsune Miku',\n            url: 'music\/world_is_mine.mp3',\n            cover: 'img\/miku_cover.jpg'\n        }\n    ]\n});<\/code><\/pre>\n<p><strong>\u6548\u679c\uff1a<\/strong> \u9875\u9762\u4e00\u6253\u5f00\uff0c\u5de6\u4e0b\u89d2\u5c31\u51fa\u73b0\u4e86\u64ad\u653e\u5668\uff0c\u70b9\u51fb\u64ad\u653e\uff0cMiku \u7684\u6b4c\u58f0\u5c31\u51fa\u6765\u4e86\u3002\u5b8c\u7f8e\uff1f\u5e76\u6ca1\u6709\u3002<\/p>\n<hr \/>\n<h2>\u7b2c\u4e8c\u9636\u6bb5\uff1a\u9047\u5230\u7684\u75db\u70b9<\/h2>\n<p>\u6211\u5174\u594b\u5730\u70b9\u51fb\u5bfc\u822a\u680f\u53bb\u67e5\u770b\u201c\u7cbe\u9009\u5c55\u5385\u201d\u9875\u9762\uff0c\u7ed3\u679c\u2026\u2026\n<strong>\u97f3\u4e50\u505c\u4e86\uff01<\/strong> \ud83d\ude31<\/p>\n<p><strong>\u539f\u56e0\u5206\u6790\uff1a<\/strong>\n\u4f20\u7edf\u7684\u7f51\u9875\u8df3\u8f6c\uff08<code>a href=&quot;page2.html&quot;<\/code>\uff09\u672c\u8d28\u4e0a\u662f\u6d4f\u89c8\u5668<strong>\u9500\u6bc1\u5f53\u524d\u9875\u9762\uff0c\u52a0\u8f7d\u65b0\u9875\u9762<\/strong>\u3002\n\u5f53\u524d\u9875\u9762\u88ab\u9500\u6bc1\u4e86\uff0c\u4f9d\u9644\u5728\u9875\u9762\u4e0a\u7684 JS \u64ad\u653e\u5668\u81ea\u7136\u4e5f\u5c31\u201c\u6302\u4e86\u201d\u3002\u5230\u4e86\u65b0\u9875\u9762\uff0c\u64ad\u653e\u5668\u91cd\u65b0\u521d\u59cb\u5316\uff0c\u97f3\u4e50\u53c8\u4ece\u5934\u5f00\u59cb\u653e\u3002<\/p>\n<p>\u8fd9\u5bf9\u4e8e\u542c\u6b4c\u4f53\u9a8c\u6765\u8bf4\u7b80\u76f4\u662f\u707e\u96be\uff01\u6211\u60f3\u8981\u7684\u662f\u7f51\u6613\u4e91\u97f3\u4e50\u90a3\u79cd\u201c\u9875\u9762\u968f\u4fbf\u5207\uff0c\u6b4c\u58f0\u6c38\u6d41\u4f20\u201d\u7684\u6548\u679c\u3002<\/p>\n<hr \/>\n<h2>\u7b2c\u4e09\u9636\u6bb5\uff1a\u91cd\u6784\uff01iframe \u4e3b\u6846\u67b6\u5927\u6cd5<\/h2>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u53c2\u8003\u4e86\u5927\u4f6c\u7684\u601d\u8def\uff0c\u51b3\u5b9a\u4f7f\u7528 <strong>iframe\uff08\u5185\u5d4c\u6846\u67b6\uff09<\/strong> \u6280\u672f\u3002<\/p>\n<h3>\u6838\u5fc3\u601d\u8def<\/h3>\n<p>\u628a\u7f51\u9875\u62c6\u6210\u201c\u5916\u58f3\u201d\u548c\u201c\u5185\u5bb9\u201d\u4e24\u90e8\u5206\uff1a<\/p>\n<ol>\n<li><strong>\u5916\u58f3 (Shell)<\/strong>\uff1a\u5305\u542b\u4fa7\u8fb9\u5bfc\u822a\u680f + \u97f3\u4e50\u64ad\u653e\u5668\u3002<strong>\u8fd9\u4e2a\u5916\u58f3\u6c38\u8fdc\u4e0d\u4f1a\u5237\u65b0<\/strong>\u3002<\/li>\n<li><strong>\u5185\u5bb9 (Content)<\/strong>\uff1a\u7528\u4e00\u4e2a `\n<iframe>` \u6807\u7b7e\u6765\u663e\u793a\u5177\u4f53\u7684\u5b50\u9875\u9762\uff08\u5982\u9996\u9875\u3001\u753b\u5eca\u9875\uff09\u3002\u5207\u6362\u9875\u9762\u65f6\uff0c\u53ea\u66ff\u6362 iframe \u91cc\u7684\u94fe\u63a5\u3002<\/iframe><\/li>\n<\/ol>\n<h3>1. \u6587\u4ef6\u7ed3\u6784\u8c03\u6574<\/h3>\n<p>\u6211\u91cd\u65b0\u89c4\u5212\u4e86\u9879\u76ee\u7ed3\u6784\uff1a<\/p>\n<pre><code>static\/\n\u251c\u2500\u2500 css\/\n\u2502   \u251c\u2500\u2500 main-frame.css      # \u4e13\u95e8\u7ed9iframe\u5e03\u5c40\u7528\u7684\n\u2502   \u2514\u2500\u2500 navbar.css          # \u5bfc\u822a\u680f\u6837\u5f0f\n\u251c\u2500\u2500 html\/\n\u2502   \u251c\u2500\u2500 main.html           # \u3010\u65b0\u5165\u53e3\u3011\u4e3b\u6846\u67b6\u5916\u58f3\n\u2502   \u251c\u2500\u2500 index.html          # \u539f\u6765\u7684\u9996\u9875\uff08\u73b0\u5728\u53d8\u6210\u5b50\u9875\u9762\uff09\n\u2502   \u2514\u2500\u2500 ...                 # \u5176\u4ed6\u9875\u9762\n\u2514\u2500\u2500 js\/\n    \u251c\u2500\u2500 main-frame.js       # \u63a7\u5236iframe\u5207\u6362\n    \u2514\u2500\u2500 music_aplayer.js    # \u64ad\u653e\u5668\u914d\u7f6e<\/code><\/pre>\n<h3>2. \u7f16\u5199\u4e3b\u6846\u67b6 (main.html)<\/h3>\n<p>\u8fd9\u662f\u6574\u4e2a\u7cfb\u7edf\u7684\u6838\u5fc3\u3002\u6211\u5728 <code>main.html<\/code> \u91cc\u5199\u4e86\u8fd9\u6837\u7684\u5e03\u5c40\uff1a<\/p>\n<pre><code class=\"lang-html language-html html\">\n&lt;body&gt;\n    &lt;iframe src=&quot;index.html&quot; id=&quot;contentFrame&quot; class=&quot;content-frame&quot; name=&quot;contentFrame&quot;&gt;&lt;\/iframe&gt;\n\n    &lt;div id=&quot;aplayer&quot;&gt;&lt;\/div&gt;\n\n    &lt;script src=&quot;..\/js\/navbar.js&quot;&gt;&lt;\/script&gt;\n    &lt;script src=&quot;..\/js\/main-frame.js&quot;&gt;&lt;\/script&gt;\n    &lt;script src=&quot;..\/js\/music_aplayer.js&quot;&gt;&lt;\/script&gt;\n&lt;\/body&gt;<\/code><\/pre>\n<h3>3. CSS \u5e03\u5c40\u9b54\u6cd5 (main-frame.css)<\/h3>\n<p>\u4e3a\u4e86\u8ba9 iframe \u770b\u8d77\u6765\u4e0d\u50cf\u4e2a\u65e7\u65f6\u4ee3\u7684\u7f51\u9875\uff0c\u6211\u4eec\u9700\u8981\u53bb\u6389\u5b83\u7684\u8fb9\u6846\uff0c\u5e76\u5904\u7406\u597d\u5c42\u7ea7\u5173\u7cfb\uff08z-index\uff09\uff1a<\/p>\n<pre><code class=\"lang-css language-css css\">.content-frame {\n    position: fixed;\n    top: 0; left: 0; right: 0; bottom: 0;\n    width: 100%; height: 100%;\n    border: none;\n    z-index: 1; \/* \u5c42\u7ea7\u6700\u4f4e\uff0c\u5728\u6700\u5e95\u5c42 *\/\n    transition: left 0.3s ease; \/* \u52a0\u4e2a\u52a8\u753b\uff0c\u4fa7\u8fb9\u680f\u5c55\u5f00\u65f6\u4e1d\u6ed1\u79fb\u52a8 *\/\n}<\/code><\/pre>\n<p>\u540c\u65f6\uff0c\u4fa7\u8fb9\u680f\u7684 <code>z-index<\/code> \u8bbe\u4e3a 1000\uff0c\u64ad\u653e\u5668\u7684 <code>fixed<\/code> \u6a21\u5f0f\u4f1a\u81ea\u52a8\u5904\u7406\u5c42\u7ea7\uff0c\u786e\u4fdd\u5b83\u4eec\u6d6e\u5728\u5185\u5bb9\u4e4b\u4e0a\u3002<\/p>\n<h3>4. \u8ba9\u5bfc\u822a\u680f\u63a7\u5236 iframe (main-frame.js)<\/h3>\n<p>\u6700\u5173\u952e\u7684\u4e00\u6b65\uff0c\u4e0d\u80fd\u8ba9 <code> &lt;a&gt;<\/code> \u6807\u7b7e\u76f4\u63a5\u8df3\u8f6c\uff0c\u800c\u662f\u8981\u62e6\u622a\u70b9\u51fb\u4e8b\u4ef6\uff0c\u628a\u76ee\u6807\u5730\u5740\u8d4b\u7ed9 iframe\uff1a<\/p>\n<pre><code class=\"lang-javascript language-javascript javascript\">\/\/ \u4f2a\u4ee3\u7801\u903b\u8f91\nlink.addEventListener('click', function(e) {\n    e.preventDefault(); \/\/ \u963b\u6b62\u6d4f\u89c8\u5668\u8df3\u8f6c\n    const targetUrl = this.getAttribute('href');\n    \/\/ \u4fee\u6539 iframe \u7684\u5730\u5740\uff0c\u5b9e\u73b0\u9875\u9762\u5c40\u90e8\u5237\u65b0\n    document.getElementById('contentFrame').src = targetUrl;\n});<\/code><\/pre>\n<hr \/>\n<h2>\u2728 \u6700\u7ec8\u6548\u679c<\/h2>\n<p>\u73b0\u5728\uff0c\u6211\u7684\u5927\u4f5c\u4e1a\u53d8\u6210\u4e86\u8fd9\u6837\uff1a<\/p>\n<ol>\n<li><strong>\u6253\u5f00 <code>main.html<\/code><\/strong>\uff1a\u9996\u5148\u770b\u5230\u9996\u9875\uff0c\u97f3\u4e50\u64ad\u653e\u5668\u5c31\u4f4d\u3002\n<img decoding=\"async\" src=\"https:\/\/gastigado.cnies.org\/d\/public\/3b634adaf0c591d51481e4a5c6f4f245.png\" alt=\"\" \/><\/li>\n<li><strong>\u70b9\u51fb\u201c\u753b\u5e08\u526f\u5c55\u5385\u201d<\/strong>\uff1a\n<ul>\n<li>\u6d4f\u89c8\u5668\u5730\u5740\u680f\u4e0d\u53d8\u3002<\/li>\n<li>\u9875\u9762\u4e2d\u95f4\u7684\u5185\u5bb9\u5e73\u6ed1\u53d8\u6210\u4e86\u65b0\u9875\u9762\u3002<\/li>\n<li><strong>\u5de6\u4e0b\u89d2\u7684 APlayer \u8fdb\u5ea6\u6761\u8fd8\u5728\u7ee7\u7eed\u8d70\uff0cMiku \u7684\u6b4c\u58f0\u5b8c\u5168\u6ca1\u6709\u4e2d\u65ad\uff01<\/strong> 3.  <strong>\u54cd\u5e94\u5f0f\u9002\u914d<\/strong>\uff1a\u5728\u624b\u673a\u4e0a\uff0c\u4fa7\u8fb9\u680f\u4f1a\u81ea\u52a8\u53d8\u6210\u906e\u7f69\u6a21\u5f0f\uff0ciframe \u4fdd\u6301\u4e0d\u52a8\uff0c\u4f53\u9a8c\u975e\u5e38 App \u5316\u3002<\/li>\n<\/ul><\/li>\n<\/ol>\n<h2>\ud83d\udcdd \u8e29\u5751\u603b\u7ed3<\/h2>\n<ol>\n<li><strong>\u8def\u5f84\u95ee\u9898<\/strong>\uff1a\u97f3\u4e50\u6587\u4ef6\u7684\u8def\u5f84\u8981\u57fa\u4e8e <code>main.html<\/code> \u7684\u4f4d\u7f6e\u5199\uff08\u6bd4\u5982 <code>..\/images\/music\/xxx.mp3<\/code>\uff09\uff0c\u800c\u4e0d\u662f\u5b50\u9875\u9762\u3002<\/li>\n<li><strong>\u5b50\u9875\u9762\u5bfc\u822a<\/strong>\uff1a\u56e0\u4e3a\u5b50\u9875\u9762\u88ab\u5d4c\u5728 iframe \u91cc\uff0c\u5982\u679c\u4e0d\u505a\u5904\u7406\uff0c\u5b50\u9875\u9762\u91cc\u53ef\u80fd\u53c8\u4f1a\u663e\u793a\u4e00\u4e2a\u5bfc\u822a\u680f\u3002\u6211\u5728 <code>navbar.js<\/code> \u91cc\u52a0\u4e86\u4e2a\u5224\u65ad <code>if (window.self !== window.top)<\/code>\uff0c\u5982\u679c\u662f\u88ab\u5d4c\u5957\u7684\u9875\u9762\uff0c\u5c31\u81ea\u52a8\u9690\u85cf\u5bfc\u822a\u680f\u3002<\/li>\n<li><strong>LRC\u6b4c\u8bcd<\/strong>\uff1aAPlayer \u652f\u6301 <code>.lrc<\/code> \u6587\u4ef6\uff0c\u53ea\u8981\u914d\u7f6e\u597d <code>lrcType: 3<\/code>\uff0c\u6b4c\u8bcd\u5c31\u80fd\u8ddf\u7740\u52a8\uff0c\u8fd9\u6ce2\u5927\u4f5c\u4e1a\u7a33\u4e86\uff01<\/li>\n<\/ol>\n<hr \/>\n<blockquote>\n<p><strong>\u7ed3\u8bed<\/strong>\n\u867d\u7136\u53ea\u662f\u52a0\u4e2a\u64ad\u653e\u5668\uff0c\u5374\u903c\u7740\u6211\u5b66\u61c2\u4e86 iframe \u548c\u5355\u9875\u5e94\u7528\uff08SPA\uff09\u7684\u96cf\u5f62\u903b\u8f91\u3002\u770b\u5230\u7f51\u9875\u5728\u5207\u6362\u65f6\u90a3\u4e1d\u6ed1\u7684\u4f53\u9a8c\uff0c\u611f\u89c9\u4e00\u5207\u6298\u817e\u90fd\u503c\u4e86\uff01<\/p>\n<p>Ciallo\uff5e(\u2220\u30fb\u03c9\\< )\u2312\u2605 \u4e0b\u6b21\u7ee7\u7eed\u6298\u817e\uff01<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u6700\u8fd1\u5728\u6413\u6211\u7684 Web \u671f\u672b\u5927\u4f5c\u4e1a\u2014\u2014\u4e00\u4e2a\u521d\u97f3\u672a\u6765\uff08Miku\uff09\u4e3b\u9898\u7684\u753b\u5eca\u7f51\u7ad9\u3002\u9875\u9762\u505a\u5f97\u5f88\u6f02\u4eae\uff0c\u4f46\u603b\u89c9\u5f97\u5c11\u4e86\u70b9\u7075\u9b42\u2026\u2026\u6ca1\u9519\uff0c\u662f  &#8230;<\/p>","protected":false},"author":1,"featured_media":220,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn"],"_links":{"self":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":1,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions\/221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/media\/220"}],"wp:attachment":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}