简体   繁体   English

无法延迟iPhone / iPad上的两个JavaScript操作

[英]Cannot delay two JavaScript actions on iPhone / iPad

I display a loading spinner to reload a custom pdf reader (in html 5) after each rotation of the device. 我显示一个加载微调器,以便在设备每次旋转后重新加载自定义pdf阅读器(HTML 5)。 It works well on an android device and when i simulate a rotation on desktop device, but on the iPad, I cannot see the spinner, it's as if the actions showing the spinner / reloading the pdf reader/ hiding the spinner are executed at a "one shot". 它在Android设备上运作良好,当我在台式机设备上模拟旋转时,但是在iPad上,我看不到微调器,就好像显示微调器/重新加载pdf阅读器/隐藏微调器的操作是在“一枪”。 I've tried to delay the pdf reloading until the spinner is shown but it's the same thing. 我试图延迟pdf重新加载,直到显示微调框,但这是同一回事。 Here is the sequence of actions : 这是动作顺序:

window.onorientationchange = function() {
           launchSpinnerThenRotate();
}

function launchSpinnerThenRotate(){
    alert(" i'll launchSpinnerThenRotate");
    showSpinner();
    setTimeout(rotatePdfReader(),1000);
}

I've tried both js and jquery functions to show / hide spinner always with the same effect 我已经尝试过js和jquery函数来始终显示/隐藏微调框

function showSpinner(){
    //$('#pdfReaderSpinner').css("visibility" , "visible");
    document.getElementById('pdfReaderSpinner').style.visibility = "visible";
    document.getElementById('pdfReaderSpinner').style.zIndex = 100000000;
}

I don't think that the problem is in spinner, I can show it correctly at the first launching of the page, but I had to show the spinner in the document.ready function : 我不认为问题出在微调器中,我可以在页面第一次启动时正确显示它,但是我必须在document.ready函数中显示微调器:

$(document).ready(function() { 
    var target = document.getElementById('loadingSpinner');
    spinner = new Spinner({top: 0, left: 0,color:'red'}).spin(target);
    showSpinner();
});

$(window).load(function(){
    initPdfReader();
    hideSpinner();
});

Change this line: 更改此行:

setTimeout(rotatePdfReader(),1000);

to this: 对此:

setTimeout(rotatePdfReader,1000);

You want to pass the reference to the function to setTimeout so it can be called in 1 second. 您希望将对函数的引用传递给setTimeout,以便可以在1秒钟内调用它。 Currently you are passing the result of the function to setTimeout. 当前,您正在将函数的结果传递给setTimeout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM