{"id":2181,"date":"2017-10-18T14:48:25","date_gmt":"2017-10-18T06:48:25","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2181"},"modified":"2017-10-18T14:48:25","modified_gmt":"2017-10-18T06:48:25","slug":"pointer-lock-api%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2181","title":{"rendered":"Pointer Lock API\u5927\u5168"},"content":{"rendered":"<p>\n\tPointer Lock API\u4e2d\u6587\u53eb\u505a\u6307\u9488\u9501\u5b9a\u6216\u8005\u9f20\u6807\u9501\u5b9a\u3002Pointer Lock API\u63d0\u4f9b\u4e86\u4e00\u79cd\u8f93\u5165\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u662f\u57fa\u4e8e\u9f20\u6807\u968f\u7740\u65f6\u95f4\u63a8\u79fb\u7684\u8fd0\u52a8\u7684\uff08\u4e5f\u5c31\u662f\u8bf4\uff0cdeltas\uff09\uff0c\u800c\u4e0d\u4ec5\u662f\u9f20\u6807\u5149\u6807\u7684\u7edd\u5bf9\u4f4d\u7f6e\u3002\u901a\u8fc7\u5b83\u53ef\u4ee5\u8bbf\u95ee\u539f\u59cb\u7684\u9f20\u6807\u8fd0\u52a8\uff0c\u628a\u9f20\u6807\u4e8b\u4ef6\u7684\u76ee\u6807\u9501\u5b9a\u5230\u4e00\u4e2a\u5355\u72ec\u7684\u5143\u7d20\uff0c\u8fd9\u5c31\u6d88\u9664\u4e86\u9f20\u6807\u5728\u4e00\u4e2a\u5355\u72ec\u7684\u65b9\u5411\u4e0a\u5230\u5e95\u53ef\u4ee5\u79fb\u52a8\u591a\u8fdc\u8fd9\u65b9\u9762\u7684\u9650\u5236\uff0c\u5e76\u4ece\u89c6\u56fe\u4e2d\u5220\u53bb\u5149\u6807\u3002&nbsp;\n<\/p>\n<p>\n\t\u7528\u4e00\u53e5\u8bdd\u8bf4\u660ePointer Lock API\u7684\u4f5c\u7528\u5c31\u662f\uff1aPointer Lock API\u53ef\u4ee5\u8ba9\u4f60\u7684\u9f20\u6807\u65e0\u9650\u79fb\u52a8\uff0c\u8131\u79bb\u6d4f\u89c8\u5668\u7a97\u4f53\u7684\u9650\u5236\uff01\n<\/p>\n<p>\n\t\u8fd9\u5bf9\u4e8e\u4e00\u4e9b\u9700\u8981\u9f20\u6807\u63a7\u5236\u7684\u5e94\u7528\u975e\u5e38\u6709\u7528\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u67d03D VR\u5973\u53cb\u7684\u6e38\u620f\uff0c\u4f60\u9f20\u6807\u5411\u4e0a\u79fb\u52a8\uff0c\u5219\u4f60\u7684\u89c6\u89d2\u5c31\u4f1a\u5f80\u4e0b\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Pointer Lock API 3D VR\u5973\u53cb\u7684\u6e38\u620f\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201710\/vr-gf-s.jpg\" style=\"width: 400px;height: 246px\" \/>\n<\/p>\n<p>\n\t\u5728\u9ed8\u8ba4\u7f51\u9875\u73af\u5883\u4e0b\uff0c\u4f60\u9f20\u6807\u79fb\u52a8\u5230\u6d4f\u89c8\u5668\u4e0a\u8fb9\u7f18\u5c31\u4e0d\u80fd\u518d\u5f80\u4e0a\u4e86\uff0c\u7ed3\u679c\uff0c\u672c\u6765\u8fd8\u5dee\u4e00\u70b9\u70b9\u89d2\u5ea6\u5c31\u80fd\u770b\u5230\u80d6\u6b21\uff0c\u7ed3\u679c\u5361\u5728\u4e86\u5173\u952e\u5730\u65b9\uff0c\u5c82\u4e0d\u975e\u5e38\u5f71\u54cd\u6e38\u620f\u4f53\u9a8c\u3002\n<\/p>\n<p>\n\t\u4f46\u662f\u5982\u679c\u4f7f\u7528\u4e86Pointer Lock API\uff0c\u5c31\u4e0d\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u9f20\u6807\u53ef\u4ee5\u65e0\u9650\u79fb\u52a8\uff0c\u5750\u6807\u53ef\u4ee5\u65e0\u9650\u589e\u5927\uff0c\u5b8c\u5168\u8131\u79bb\u4e86\u6d4f\u89c8\u5668\u7a97\u53e3\u7684\u9650\u5236\uff0c\u53ef\u4ee5\u5b8c\u7f8e\u4eab\u53d7\u6c89\u6d78\u5f0f\u64cd\u4f5c\u4f53\u9a8c\u3002\n<\/p>\n<p>\n\t\u76ee\u524d\uff0cPointer Lock API\u5171\u652f\u63013\u4e2a\u5c5e\u6027\uff0c2\u4e2a\u65b9\u6cd5\u548c2\u4e2a\u4e8b\u4ef6\uff0c\u5206\u522b\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t3\u4e2a\u5c5e\u6027\uff1a\n<\/p>\n<ul>\n<li>\n\t\tDocument.pointerLockElement\n\t<\/li>\n<li>\n\t\tDocument.onpointerlockchange\n\t<\/li>\n<li>\n\t\tDocument.onpointerlockerror\n\t<\/li>\n<\/ul>\n<p>\n\t2\u4e2a\u65b9\u6cd5\uff1a\n<\/p>\n<ul>\n<li>\n\t\tElement.requestPointerLock()\n\t<\/li>\n<li>\n\t\tDocument.exitPointerLock()\n\t<\/li>\n<\/ul>\n<p>\n\t2\u4e2a\u4e8b\u4ef6\n<\/p>\n<ul>\n<li>\n\t\tpointerlockchange\n\t<\/li>\n<li>\n\t\tpointerlockerror\n\t<\/li>\n<\/ul>\n<p>\n\t\u5176\u4e2d\uff0c2\u4e2a\u4e8b\u4ef6\u548c\u5176\u4e2d2\u4e2a\u5c5e\u6027\u662f\u4e00\u4e00\u5bf9\u5e94\u7684\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u5b9e\u9645\u4e0a\u9700\u8981\u4e86\u89e3\u7684\u77e5\u8bc6\u70b9\u662f\u4e0b\u9762\u8fd9\u4e9b\uff1a<br \/>\n\tDocument.pointerLockElement\uff0c\u4ee5\u53caElement.requestPointerLock()\uff0cDocument.exitPointerLock()\u4ee5\u53capointerlockchange\u548cpointerlockerror\u4e8b\u4ef6\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u4e00\u4e00\u7684\u4ecb\u7ecd\u4ed6\u4eec\u7684\u7528\u6cd5\u3002\n<\/p>\n<h2>\n\tDocument.pointerLockElement<br \/>\n<\/h2>\n<p>\n\t\u6307\u5f53\u524d\u9875\u9762\u89e6\u53d1\u9f20\u6807\u65e0\u9650\u6eda\u52a8\u7684\u5143\u7d20\uff0c\u901a\u5e38\u4f7f\u7528\u8bed\u6cd5\u4e3a\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar element = document.pointerLockElement;<\/pre>\n<p>\n\t\u8fd4\u56de\u7684\u662f\u4e00\u4e2aDOM\u5143\u7d20\u5bf9\u8c61\uff0c\u5982\u679c\u5f53\u524d\u9875\u9762\u662f\u975e\u9f20\u6807\u9501\u5b9a\u72b6\u6001\uff0c\u5219\u8fd4\u56de\u503c\u662fnull\u3002\n<\/p>\n<h2>\n\tElement.requestPointerLock()<br \/>\n<\/h2>\n<p>\n\t\u53ef\u4ee5\u8ba9\u9875\u9762\u8fdb\u5165\u9f20\u6807\u9501\u5b9a\u72b6\u6001\uff08\u9f20\u6807\u76f4\u63a5\u6d88\u5931\uff09\uff0c\u9f20\u6807\u65e0\u9650\u6eda\u52a8\uff0c\u5750\u6807\u65e0\u9650\u53d8\u5316\u3002\u901a\u5e38\u4f7f\u7528\u8bed\u6cd5\u4e3a\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar element.requestPointerLock();<\/pre>\n<h2>\n\tDocument.exitPointerLock()<br \/>\n<\/h2>\n<p>\n\t\u8ba9\u9875\u9762\u4ece\u9f20\u6807\u9501\u5b9a\u72b6\u6001\u9000\u51fa\uff0c\u901a\u5e38\u4f7f\u7528\u8bed\u6cd5\u4e3a\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\ndocument.exitPointerLock();<\/pre>\n<p>\n\t\u6d4f\u89c8\u5668\u9ed8\u8ba4\u652f\u6301\u6309\u4e0bESC\u952e\u9000\u51fa\u9f20\u6807\u9501\u5b9a\u72b6\u6001\uff0c\u4f46\u662f\u7528\u6237\u6709\u65f6\u5019\u66f4\u4e60\u60ef\u4e8e\u70b9\u51fb\u53d6\u6d88\u7b49\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528document.exitPointerLock()\u8fdb\u884c\u8bbe\u7f6e\u3002\n<\/p>\n<h2>\n\tpointerlockchange\u4e8b\u4ef6<br \/>\n<\/h2>\n<p>\n\t\u5f53\u9875\u9762\u9f20\u6807\u9501\u5b9a\u72b6\u6001\u6539\u53d8\u7684\u65f6\u5019\u89e6\u53d1\u3002\u4f8b\u5982\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\ndocument.addEventListener(&#039;pointerlockchange&#039;, function () {\r\n    \/\/ ...\r\n}, false);<\/pre>\n<h2>\n\tpointerlockerror\u4e8b\u4ef6<br \/>\n<\/h2>\n<p>\n\t\u5f53\u9875\u9762\u9f20\u6807\u9501\u5b9a\u5931\u8d25\u7684\u65f6\u5019\u89e6\u53d1\u3002\u4f8b\u5982\u5f53\u4f60\u8bd5\u56fe\u540c\u65f6\u9501\u5b9a\u540c\u4e00\u4e2a\u9875\u9762\u7684\u591a\u4e2a&lt;iframe&gt;\u65f6\u5019\uff0c\u5c31\u4f1a\u89e6\u53d1\u8fd9\u4e2a\u51fa\u9519\u4e8b\u4ef6\u3002\n<\/p>\n<p>\n\t\u672c\u6587\u53ea\u662f\u4ecb\u7ecd\u4e86Pointer Lock API\u7684\u5c5e\u6027\uff0c\u4e8b\u4ef6\u548c\u65b9\u6cd5\uff0c\u4e0b\u9762\u6211\u4eec\u518d\u6765\u4e00\u7bc7\u5b9e\u6218\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2181\">Pointer Lock API\u5927\u5168<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>Pointer Lock API\u4e2d\u6587\u53eb\u505a\u6307\u9488\u9501\u5b9a\u6216\u8005\u9f20\u6807\u9501\u5b9a\u3002Pointer Lock API\u63d0\u4f9b\u4e86\u4e00\u79cd\u8f93\u5165\u65b9 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1106],"class_list":["post-2181","post","type-post","status-publish","format-standard","hentry","category-html5","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2181"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions"}],"predecessor-version":[{"id":2182,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions\/2182"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}