基本的に私がやろうとしているのは、赤いブロックを画面の左側から右側に移動させることです。私が直面している問題は、ページがアニメーションを表示せずに Java スクリプトを実行することです。ユーザーがJavaScriptの実行を完了するのを待っている間、ブロックは画面の反対側に移動されます。jQuery を使用してみましたが、それでも同じ結果が得られます。どんな助けでも大歓迎です。
私が持っている私の体の最後にある私のHTMLコードでOK:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="js/nexusStyle.js"></script>
<script>
$(document).append(function foo(){
start();
});
</script>
そして、私の nexusStyle.js ファイルには次のものがあります。
function start(){
createBlock();
var mHeight = getMonitorHeight();
var mWidth = getMonitorWidth();
}
function getMonitorWidth() {
return screen.width;
}
function getMonitorHeight(){
return screen.height;
}
function horizontalMotion(maxWidth, img){
for(var i=0; parseInt(i)<maxWidth; i+=50){
img.style.left = i+"px";
sleep(100);
}
}
function sleep(delay){
var start = new Date().getTime();
while(new Date().getTime()<start+delay);
}
function createBlock(){
var img, left, top, interval;
interval = 100;
img = document.createElement('img');
img.src = "img/blocks/redBlock.png";
left = 0;
top = 200;
img.style.position = "absolute";
img.style.left = left+"px";
img.style.top = top+"px";
document.body.appendChild(img);
horizontalMotion(getMonitorWidth(), img);
}