【发布时间】:2018-01-12 00:59:41
【问题描述】:
我有以下代码来检查是否有陀螺仪可供用户交互。我通过以下方式执行此操作:
function check_user_hardware(){
window.addEventListener("devicemotion", function(event){
if(event.rotationRate.alpha || event.rotationRate.beta || event.rotationRate.gamma){
if (!gyroscope) {
gyroscope = true;
current_interaction_mode = 'gyroscope_option';
set_user_ui_elements();
}
}else{
followMouse = true;
current_interaction_mode = 'followMouse_option';
console.log("checked for motion");
set_user_ui_elements();
window.addEventListener('mousemove', get_user_mouse_pos);
}
calculate_rotation_mesh_pos(event.rotationRate.beta, event.rotationRate.gamma);
}, function(){
console.log("generate_scene???");
generate_scene();
});
}
我遇到的问题是在此检查之后生成了一些场景。
但是这个场景需要首先在检查中设置一个 var。但是检查需要很长时间,所以我在检查完成后添加了一个回调。
但是这个回调永远不会触发......为什么?换句话说,generate_scene??? 永远不会被记录,generate_scene(); 永远不会运行。
为什么会这样?什么是正确的方法?
如果有什么不清楚的地方请告诉我,以便我澄清:)
【问题讨论】:
标签: javascript jquery callback three.js