我试图让地理定位表单允许,阻止在函数运行完成后出现。此时,即使使用回调,地理定位也不会等待 Jquery 操作完成。
我正在使用 typeIt jquery 插件来显示一些文本,在所有文本出现后,应该向用户显示地理定位框。
这是我现在拥有的:
function typeThen(callback) {
$(".text").typeIt({
speed: 30,
cursor: false
})
.tiType("Meow! ")
.tiPause(1000)
.tiBreak()
.tiType("Please, share your location with us. Oh, and don't be afraid... ")
.tiPause(750)
.tiType("cats are very good at keeping secrets! :3")
callback && callback();
}
function getLocation() {
navigator.geolocation.getCurrentPosition(sendLocation, geoError);
}
typeThen(function(){
getLocation();
});
最佳答案
callback - (function) A function that executes after your typing has completed.
所以只需使用它:
$(".text").typeIt({
speed: 30,
cursor: false,
callback : function(){
callback()
})
})
或者甚至简单地:
$(".text").typeIt({
speed: 30,
cursor: false,
callback : callback
})
关于javascript - 地理位置表单不等待回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45905577/