0
我想將鼠標鎖定到畫布元素。 畫布元素存在並且指針鎖定可用。畫布指針鎖
這裏是我的控制檯輸出:
- 指針鎖存在
- 沒有鎖定
- 出現錯誤
已經檢查這兩個環節,但找不到我的錯。由於不再需要全屏來實現指針鎖,因此我沒有啓動全屏。
http://www.html5rocks.com/en/tutorials/pointerlock/intro/
https://developer.mozilla.org/en-US/docs/WebAPI/Pointer_Lock
當然我也有對pointlocker退出功能。但我想這個問題不會在那裏。
var check_pointerLock = 'pointerLockElement' in document ||
'mozPointerLockElement' in document ||
'webkitPointerLockElement' in document;
if(check_pointerLock){
console.log("Pointer lock exists");
//canvas element to lock pointer to
canvas.requestPointerLock = canvas.requestPointerLock ||
canvas.mozRequestPointerLock ||
canvas.webkitRequestPointerLock;
canvas.requestPointerLock();
//check for errors
document.addEventListener('pointerlockerror', errorCallback, false);
document.addEventListener('mozpointerlockerror', errorCallback, false);
document.addEventListener('webkitpointerlockerror', errorCallback, false);
// 1) Used as a boolean check: are we pointer locked?
if (!!document.pointerLockElement) {
console.log("locked");
} else {
// pointer is not locked
console.log("not locked");
}
}
function errorCallback() {
console.log("There was an error");
}