{"id":3813,"date":"2024-11-10T09:04:22","date_gmt":"2024-11-10T01:04:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3813\/"},"modified":"2024-11-10T09:04:22","modified_gmt":"2024-11-10T01:04:22","slug":"%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e7%a6%bb%e5%bc%80%e9%a1%b5%e9%9d%a2%e6%97%b6%e5%ae%9a%e6%97%b6%e5%99%a8%e5%8a%a0%e9%80%9f%e5%85%83%e7%b4%a0%e8%bf%90%e5%8a%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3813\/","title":{"rendered":"\u5982\u4f55\u907f\u514d\u79bb\u5f00\u9875\u9762\u65f6\u5b9a\u65f6\u5668\u52a0\u901f\u5143\u7d20\u8fd0\u52a8\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173114625273028.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u907f\u514d\u79bb\u5f00\u9875\u9762\u65f6\u5b9a\u65f6\u5668\u52a0\u901f\u5143\u7d20\u8fd0\u52a8\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u907f\u514d\u79bb\u5f00\u9875\u9762\u65f6\u5b9a\u65f6\u5668\u52a0\u901f\u5143\u7d20\u8fd0\u52a8\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b9a\u65f6\u5668\u4e2d\u65ad\u7684\u89e3\u51b3\u529e\u6cd5<\/strong><\/p>\n<p>\u5f53\u6211\u4eec\u79bb\u5f00\u5f53\u524d\u9875\u9762\u65f6\uff0c\u5b9a\u65f6\u5668\u5374\u6ca1\u6709\u88ab\u6e05\u9664\uff0c\u5c31\u4f1a\u5bfc\u81f4\u539f\u672c\u5300\u901f\u8fd0\u52a8\u7684\u5143\u7d20\u52a0\u901f\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u76d1\u542c\u9875\u9762\u662f\u5426\u5728\u6d4f\u89c8\u5668\u5f53\u524d\u9875\u3002<\/p>\n<p><strong>\u4f7f\u7528 document.hidden<\/strong><\/p>\n<ul>\n<li><strong>\u4e0d\u8003\u8651\u517c\u5bb9\u6027\u5199\u6cd5\uff1a<\/strong><\/li>\n<\/ul>\n<pre>document.addeventlistener(\"visibilitychange\", function () {\n    if (!document.hidden) {\n        \/\/ \u5904\u4e8e\u5f53\u524d\u9875\u9762\n        timer = setinterval(() =&gt; {\n            rotate();\n        }, 1000);\n        console.log(\"active\");\n    } else {\n        clearinterval(timer);\n        console.log(\"hidden\");\n    }\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li><strong>\u8003\u8651\u517c\u5bb9\u6027\u5199\u6cd5\uff1a<\/strong><\/li>\n<\/ul>\n<pre>var hiddenProperty = 'hidden' in document ? 'hidden' :\n    'webkitHidden' in document ? 'webkitHidden' :\n        'mozHidden' in document ? 'mozHidden' :\n            null;\nvar visibilityChangeEvent = hiddenProperty.replace(\/hidden\/i, 'visibilitychange');\nvar onVisibilityChange = function () {\n    if (!document[hiddenProperty]) {\n        rotate();  \/\/ \u65e0\u95f4\u9699\u65cb\u8f6c\n        timer = setInterval(() =&gt; {\n            rotate();\n        }, 1000);\n        console.log(hiddenProperty);\n    } else {\n        clearInterval(timer)\n        timer\n    }\n}\ndocument.addEventListener(visibilityChangeEvent, onVisibilityChange);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u907f\u514d\u79bb\u5f00\u9875\u9762\u65f6\u5b9a\u65f6\u5668\u52a0\u901f\u5143\u7d20\u8fd0\u52a8\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>\u5b9a\u65f6\u5668\u4e2d\u65ad\u7684\u89e3\u51b3\u529e\u6cd5 \u5f53\u6211\u4eec\u79bb\u5f00\u5f53\u524d\u9875\u9762\u65f6\uff0c\u5b9a\u65f6\u5668\u5374\u6ca1\u6709\u88ab\u6e05\u9664\uff0c\u5c31\u4f1a\u5bfc\u81f4\u539f\u672c\u5300\u901f\u8fd0\u52a8\u7684\u5143\u7d20\u52a0\u901f\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u76d1\u542c\u9875\u9762\u662f\u5426\u5728\u6d4f\u89c8\u5668\u5f53\u524d\u9875\u3002 \u4f7f\u7528 document.hidden \u4e0d\u8003\u8651\u517c\u5bb9\u6027\u5199\u6cd5\uff1a document.addeventlistener(&#8220;visibilitychange&#8221;, function () { if (!document.hidden) { \/\/ \u5904\u4e8e\u5f53\u524d\u9875\u9762 timer = setinterval(() =&gt; { rotate(); }, 1000); console.log(&#8220;active&#8221;); } else { clearinterval(timer); console.log(&#8220;hidden&#8221;); } }); \u767b\u5f55\u540e\u590d\u5236 \u8003\u8651\u517c\u5bb9\u6027\u5199\u6cd5\uff1a var hiddenProperty = &#8216;hidden&#8217; in document ? &#8216;hidden&#8217; : &#8216;webkitHidden&#8217; in document ? &#8216;webkitHidden&#8217; : &#8216;mozHidden&#8217; in document ? &#8216;mozHidden&#8217; : null; var [&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-3813","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3813","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=3813"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3813\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}