{"id":94,"date":"2026-03-04T21:48:14","date_gmt":"2026-03-04T13:48:14","guid":{"rendered":"https:\/\/www.yanjiu.xin\/?p=94"},"modified":"2026-03-22T22:44:57","modified_gmt":"2026-03-22T14:44:57","slug":"bgapi","status":"publish","type":"post","link":"https:\/\/www.yanjiu.xin\/index.php\/bgapi\/","title":{"rendered":"\u968f\u673a\u56fe\u7247api\u5206\u4eab"},"content":{"rendered":"\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-f1cce02c4b072175246e2b4f457d99e8\"><a href=\"https:\/\/api.worlds.xin\/random.js\" target=\"_blank\" rel=\"noreferrer noopener\">\u9759\u6001api\u2460\uff1ahttps:\/\/api.worlds.xin\/random.js<\/a><\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-c2dccc31fb8f724c8384cc7d91250b97\"><a href=\"https:\/\/img.cf.worlds.xin\/random.js\" target=\"_blank\" rel=\"noreferrer noopener\">\u9759\u6001api\u2461\uff1ahttps:\/\/img.cf.worlds.xin\/random.js<\/a><\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-2cfc7514cd854defb4740af8e53209a5\"><a href=\"https:\/\/img.api.yanjiu.xin\/index.php?type=\" target=\"_blank\" rel=\"noreferrer noopener\">\u52a8\u6001api\uff1ahttps:\/\/img.api.yanjiu.xin\/index.php?type=h(v)<\/a><\/p>\n\n\n\n<!DOCTYPE html>\n<html lang=\"zh\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u9759\u6001\u968f\u673a\u56fe API \u4f7f\u7528\u8bf4\u660e<\/title>\n    <style>\n        \/* \u57fa\u7840\u6837\u5f0f\u2014\u2014\u7b80\u6d01\u3001\u5e72\u51c0\uff0c\u9002\u914d\u591a\u6570WordPress\u4e3b\u9898 *\/\n        body {\n            font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n            line-height: 1.6;\n            color: #333;\n            max-width: 900px;\n            margin: 0 auto;\n            padding: 20px;\n            background: #fff;\n        }\n        h1, h2, h3 {\n            margin-top: 2em;\n            margin-bottom: 0.5em;\n            font-weight: 600;\n            line-height: 1.25;\n        }\n        h1 { font-size: 2.2em; border-bottom: 2px solid #f0f0f0; padding-bottom: 0.3em; }\n        h2 { font-size: 1.8em; border-bottom: 1px solid #eaecef; padding-bottom: 0.2em; }\n        h3 { font-size: 1.4em; }\n        p { margin: 1em 0; }\n        a { color: #0366d6; text-decoration: none; }\n        a:hover { text-decoration: underline; }\n        ul, ol { margin: 1em 0 1em 1.5em; }\n        li { margin: 0.5em 0; }\n        code {\n            font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;\n            background: #f6f8fa;\n            padding: 0.2em 0.4em;\n            border-radius: 3px;\n            font-size: 0.9em;\n        }\n        pre {\n            background: #f6f8fa;\n            padding: 16px;\n            border-radius: 6px;\n            overflow-x: auto;\n            line-height: 1.45;\n            font-size: 0.9em;\n            border: 1px solid #e1e4e8;\n        }\n        pre code {\n            background: none;\n            padding: 0;\n            border-radius: 0;\n            font-size: inherit;\n        }\n        blockquote {\n            padding: 0 1em;\n            color: #6a737d;\n            border-left: 0.25em solid #dfe2e5;\n            margin: 1em 0;\n        }\n        hr {\n            height: 0.25em;\n            background-color: #e1e4e8;\n            border: 0;\n            margin: 24px 0;\n        }\n        .note {\n            background: #fffbdd;\n            padding: 12px 16px;\n            border-radius: 6px;\n            border-left: 4px solid #f1c40f;\n            margin: 1.5em 0;\n        }\n        .btn-copy-hint {\n            font-size: 0.85em;\n            color: #6a737d;\n            float: right;\n        }\n        \/* \u9488\u5bf9WordPress\u5185\u5bb9\u5bb9\u5668\u7684\u989d\u5916\u4f18\u5316 *\/\n        .wp-content {\n            word-wrap: break-word;\n        }\n    <\/style>\n<\/head>\n<body>\n<div class=\"wp-content\">\n    <h1>\ud83d\uddbc\ufe0f \u9759\u6001\u968f\u673a\u56fe API \u4f7f\u7528\u6587\u6863<\/h1>\n    <p>\u611f\u8c22\u4f7f\u7528\u9759\u6001\u968f\u673a\u56fe API\uff01\u8fd9\u662f\u4e00\u4e2a\u7eaf\u524d\u7aef\u7684\u968f\u673a\u56fe\u7247\u89e3\u51b3\u65b9\u6848\uff0c\u53ea\u9700\u5728\u9875\u9762\u4e2d\u5f15\u5165\u4e00\u4e2a JS \u6587\u4ef6\uff0c\u5373\u53ef\u81ea\u52a8\u4e3a\u80cc\u666f\u3001\u56fe\u7247\u5143\u7d20\u8bbe\u7f6e\u968f\u673a\u56fe\u50cf\uff0c\u5e76\u652f\u6301\u624b\u52a8\u8c03\u7528\u83b7\u53d6\u56fe\u7247 URL\u3002<\/p>\n\n    <h2>\ud83d\ude80 \u5feb\u901f\u5f00\u59cb<\/h2>\n    <p>\u5728\u4f60\u7684 HTML \u9875\u9762\u4e2d\u5f15\u5165\u4ee5\u4e0b\u811a\u672c\uff08\u5efa\u8bae\u653e\u5728 <code>&lt;head&gt;<\/code> \u6216 <code>&lt;\/body&gt;<\/code> \u524d\uff09\uff1a<\/p>\n    <pre class=\"prettyprint linenums\" ><code>&lt;script src=\"https:\/\/api.worlds.xin\/random.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n    <p>\u65e0\u9700\u4efb\u4f55\u914d\u7f6e\uff0c\u811a\u672c\u52a0\u8f7d\u540e\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u9875\u9762\u4e2d\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002<\/p>\n\n    <h2>\ud83d\uddbc\ufe0f \u529f\u80fd\u7279\u6027<\/h2>\n    <ul>\n        <li><strong>\u4f1a\u8bdd\u4fdd\u6301<\/strong>\uff1a\u540c\u4e00\u6807\u7b7e\u9875\u5185\uff0c\u6a2a\u5c4f\/\u7ad6\u5c4f\u56fe\u7247\u5728\u6574\u4e2a\u4f1a\u8bdd\u4e2d\u4fdd\u6301\u4e0d\u53d8\uff08\u5237\u65b0\u9875\u9762\u4e0d\u4f1a\u53d8\u5316\uff0c\u91cd\u65b0\u6253\u5f00\u9875\u9762\u4f1a\u66f4\u65b0\uff09\u3002<\/li>\n        <li><strong>\u81ea\u52a8\u9884\u52a0\u8f7d<\/strong>\uff1a\u80cc\u666f\u56fe\u4f1a\u5728\u5b8c\u5168\u52a0\u8f7d\u540e\u624d\u663e\u793a\uff0c\u907f\u514d\u95ea\u70c1\u3002<\/li>\n        <li><strong>CSS \u53d8\u91cf\u652f\u6301<\/strong>\uff1a\u4e3a\u4e3b\u80cc\u666f\u81ea\u52a8\u8bbe\u7f6e\u900f\u660e\u6548\u679c\u53d8\u91cf\u3002<\/li>\n        <li><strong>Swup \u96c6\u6210<\/strong>\uff1a\u81ea\u52a8\u76d1\u542c Swup \u9875\u9762\u5207\u6362\u4e8b\u4ef6\uff0c\u91cd\u65b0\u521d\u59cb\u5316\u56fe\u7247\u3002<\/li>\n    <\/ul>\n\n    <h2>\ud83d\udcdd \u4f7f\u7528\u65b9\u5f0f<\/h2>\n\n    <h3>1. \u8bbe\u7f6e\u4e3b\u80cc\u666f\uff08\u5b9a\u5236\u7248\uff09<\/h3>\n    <p>\u5982\u679c\u4f60\u5e0c\u671b\u4e3a\u9875\u9762\u8bbe\u7f6e\u4e00\u4e2a<strong>\u6a2a\u5c4f\u80cc\u666f\u56fe<\/strong>\uff0c\u5e76\u81ea\u52a8\u83b7\u5f97\u900f\u660e\u6548\u679c\u76f8\u5173\u7684 CSS \u53d8\u91cf\uff0c\u53ea\u9700\u5728\u9875\u9762\u4e2d\u6dfb\u52a0\u4e00\u4e2a <code>id<\/code> \u4e3a <code>bg-box<\/code> \u7684\u5143\u7d20\uff1a<\/p>\n    <pre class=\"prettyprint linenums\" ><code>&lt;div id=\"bg-box\" class=\"transition-opacity duration-500 opacity-0 loaded:opacity-100\"&gt;\n    &lt;!-- \u4f60\u7684\u9875\u9762\u5185\u5bb9\u653e\u5728\u8fd9\u91cc --&gt;\n&lt;\/div&gt;<\/code><\/pre>\n    <ul>\n        <li>\u56fe\u7247\u52a0\u8f7d\u6210\u529f\u540e\uff0c<code>bg-box<\/code> \u4f1a\u81ea\u52a8\u6dfb\u52a0 <code>loaded<\/code> \u7c7b\u540d\uff0c\u5e76\u8bbe\u7f6e <code>background-image<\/code>\u3002<\/li>\n        <li>\u540c\u65f6\u4f1a\u8bbe\u7f6e\u4e24\u4e2a CSS \u53d8\u91cf\uff1a<code>--card-bg<\/code> \u548c <code>--float-panel-bg<\/code>\uff08\u900f\u660e\u7248\u672c\uff09\uff0c\u65b9\u4fbf\u4f60\u5b9e\u73b0\u6bdb\u73bb\u7483\u7b49\u6548\u679c\u3002<\/li>\n    <\/ul>\n\n    <h3>2. \u8bbe\u7f6e\u901a\u7528\u80cc\u666f\u56fe\uff08\u5907\u7528\u65b9\u6848\uff09<\/h3>\n    <p>\u5982\u679c\u9700\u8981\u4e3a\u9875\u9762\u4e2d\u7684\u5176\u4ed6\u5143\u7d20\u8bbe\u7f6e\u968f\u673a\u80cc\u666f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>data-random-bg<\/code> \u5c5e\u6027\uff0c\u5e76\u6307\u5b9a\u7c7b\u578b\uff1a<\/p>\n    <pre class=\"prettyprint linenums\" ><code>&lt;!-- \u6a2a\u5c4f\u80cc\u666f --&gt;\n&lt;div data-random-bg=\"h\" class=\"bg-element\"&gt;...&lt;\/div&gt;\n\n&lt;!-- \u7ad6\u5c4f\u80cc\u666f --&gt;\n&lt;div data-random-bg=\"v\" class=\"bg-element\"&gt;...&lt;\/div&gt;<\/code><\/pre>\n    <p>\u56fe\u7247\u52a0\u8f7d\u6210\u529f\u540e\uff0c\u8be5\u5143\u7d20\u4e5f\u4f1a\u88ab\u6dfb\u52a0 <code>loaded<\/code> \u7c7b\u540d\u3002<\/p>\n\n    <h3>3. \u8bbe\u7f6e\u666e\u901a\u56fe\u7247<\/h3>\n    <p>\u5bf9\u4e8e <code>&lt;img&gt;<\/code> \u6807\u7b7e\uff0c\u901a\u8fc7 <code>alt<\/code> \u5c5e\u6027\u6307\u5b9a\u7c7b\u578b\uff1a<\/p>\n    <pre class=\"prettyprint linenums\" ><code>&lt;!-- \u6a2a\u5c4f\u56fe\u7247 --&gt;\n&lt;img alt=\"random:h\" \/&gt;\n\n&lt;!-- \u7ad6\u5c4f\u56fe\u7247 --&gt;\n&lt;img alt=\"random:v\" \/&gt;<\/code><\/pre>\n\n    <h3>4. \u624b\u52a8\u8c03\u7528\uff08\u9ad8\u7ea7\uff09<\/h3>\n    <p>\u811a\u672c\u5728 <code>window<\/code> \u5bf9\u8c61\u4e0a\u66b4\u9732\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u4f9b\u4f60\u624b\u52a8\u83b7\u53d6\u968f\u673a\u56fe\u7247 URL\uff08\u8fd4\u56de\u503c\u5728\u5f53\u524d\u4f1a\u8bdd\u4e2d\u4fdd\u6301\u4e00\u81f4\uff09\uff1a<\/p>\n    <pre class=\"prettyprint linenums\" ><code>\/\/ \u83b7\u53d6\u6a2a\u5c4f\u56fe URL\nconst hUrl = window.getRandomPicH();\n\n\/\/ \u83b7\u53d6\u7ad6\u5c4f\u56fe URL\nconst vUrl = window.getRandomPicV();\n\n\/\/ \u793a\u4f8b\uff1a\u624b\u52a8\u8bbe\u7f6e\u56fe\u7247\ndocument.getElementById('my-image').src = hUrl;<\/code><\/pre>\n\n    <h2>\ud83d\uddbc\ufe0f \u753b\u5eca\u9875\u9762<\/h2>\n    <p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u94fe\u63a5\u6d4f\u89c8\u6240\u6709\u5df2\u4e0a\u4f20\u7684\u968f\u673a\u56fe\u7247\uff1a<\/p>\n    <p>\ud83d\udc49 <a href=\"https:\/\/api.worlds.xin\/gallery.html\" target=\"_blank\">https:\/\/api.worlds.xin\/gallery.html<\/a><\/p>\n\n    <h2>\u2699\ufe0f \u6280\u672f\u7ec6\u8282<\/h2>\n    <ul>\n        <li>\u56fe\u7247\u603b\u6570\uff1a\u6a2a\u5c4f <strong>160<\/strong> \u5f20\uff0c\u7ad6\u5c4f <strong>4<\/strong> \u5f20\u3002<\/li>\n        <li>\u56fe\u7247\u683c\u5f0f\uff1aWebP\u3002<\/li>\n        <li>URL \u683c\u5f0f\uff1a<code>https:\/\/api.worlds.xin\/ri\/{type}\/{\u6570\u5b57}.webp<\/code>\uff08<code>type<\/code> \u4e3a <code>h<\/code> \u6216 <code>v<\/code>\uff09\u3002<\/li>\n        <li>\u811a\u672c\u4ec5\u4f9d\u8d56\u6d4f\u89c8\u5668\u539f\u751f API\uff0c\u65e0\u4efb\u4f55\u5916\u90e8\u4f9d\u8d56\u3002<\/li>\n    <\/ul>\n\n    <h2>\ud83d\udccc \u6ce8\u610f\u4e8b\u9879<\/h2>\n    <ul>\n        <li>\u56fe\u7247\u5e93\u7531\u670d\u52a1\u7aef\u7ef4\u62a4\uff0c\u5982\u9700\u66f4\u65b0\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458\u91cd\u65b0\u8fd0\u884c\u6784\u5efa\u811a\u672c\u3002<\/li>\n        <li>\u7531\u4e8e\u662f\u9759\u6001 API\uff0c\u4e0d\u652f\u6301\u52a8\u6001\u4e0a\u4f20\u6216\u5220\u9664\u56fe\u7247\u3002<\/li>\n        <li>\u82e5\u9875\u9762\u4f7f\u7528\u4e86 Swup\uff0c\u811a\u672c\u4f1a\u81ea\u52a8\u76d1\u542c <code>swup:contentReplaced<\/code> \u548c <code>swup:enable<\/code> \u4e8b\u4ef6\uff0c\u65e0\u9700\u989d\u5916\u5904\u7406\u3002<\/li>\n    <\/ul>\n\n    <div class=\"note\">\n        <strong>\ud83c\udd98 \u652f\u6301<\/strong><br>\n        \u5982\u6709\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458\u3002\u611f\u8c22\u4f7f\u7528\uff01\n    <\/div>\n<\/div>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>\u9759\u6001api\u2460\uff1ahttps:\/\/api.worlds.xin\/random.js \u9759\u6001api\u2461\uff1ahttps:\/\/img.cf.worlds.xin\/random.js \u52a8\u6001api\uff1ahttps:\/\/img.api.yanjiu.xin\/index.php?type=h(v) \u9759\u6001\u968f\u673a\u56fe API \u4f7f\u7528\u8bf4\u660e \ud83d\uddbc\ufe0f \u9759\u6001\u968f\u673a\u56fe API \u4f7f\u7528\u6587\u6863 \u611f\u8c22\u4f7f\u7528\u9759\u6001\u968f\u673a\u56fe API\uff01\u8fd9\u662f\u4e00\u4e2a\u7eaf\u524d\u7aef\u7684\u968f\u673a\u56fe\u7247\u89e3\u51b3\u65b9\u6848\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[9,10],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-5","category-3","tag-api","tag-10"],"_links":{"self":[{"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":15,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanjiu.xin\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}