これは私の課題 Web サイトの JavaScript 部分です。出会い系広告を表示し、間隔を置いて画面上を移動し、間隔ごとに新しい画像をロードする必要があります。
ランダムに水平方向に移動しますが、垂直方向には移動しません。この問題は Firefox で発生します。IE では問題ありません。
ただし、IE では画像を反復しませんが、Firefox では反復します。
何が起こっているのか誰か教えてもらえますか?
<script type="text/javascript">
var rotatingAd = new Array(3);
var curPosition = 1;
var screenWidth = 0;
var screenHeight = 0;
for(var i = 0; i < 4; ++i)
{
rotatingAd[i] = new Image();
rotatingAd[i].src = "AdDate" + i + ".gif";
}
function openOrderForm()
{
window.open("order.html");
}
function moveAd(){
var leftPos = getRandomLeft();
var topPos = getRandomTop();
document.getElementById("AdDate").style.top = topPos; + "px";//this is where firefox says the css error is
document.getElementById("AdDate").style.left = leftPos + "px";
if(curPosition == 3)
{
curPosition = 0;
}
document.AdDatePic.src = rotatingAd[curPosition].src;//this is where IE gets its null error from
curPosition++;
}
function start(){
screenWidth = document.body.clientWidth;
screenHeight= document.body.clientHeight;
//alert("width="+screenWidth + "height="+screenHeight)
//setTimeout("moveAd()", 3000);
setInterval("moveAd()", 2000);
}
function getRandomLeft(){
var lpos;
lpos = Math.floor(Math.random()*(screenWidth -400));
return lpos;
}
function getRandomTop(){
tpos = Math.floor(Math.random()*(screenHeight - 135));
return tpos;
}
</script>
<body onload="start();">
<span id="AdDate" style="position:absolute; left:300px; top:300px;" >
<img id="AdDatePic" src="AdDate0.gif" alt="picture of gopher" />
</span>
</body>