Javascript 使图像每隔几秒钟以div的形式随机出现。。。怎么用?

Javascript 使图像每隔几秒钟以div的形式随机出现。。。怎么用?,javascript,html,image,Javascript,Html,Image,简单的问题,我有这个分区,400*250像素。我有这张图片,fooi.png。 如何使fooi.png每隔2秒随机出现在该div中的某个位置(并且不会删除已经出现的其他图像) 编辑: 我得到的是: function placeimage(){ $('#div').append('<img src="fooi.png" alt="image" id="'. Math.floor(Math.random()*55) .'" onclick="doclic

简单的问题,我有这个分区,400*250像素。我有这张图片,fooi.png。 如何使fooi.png每隔2秒随机出现在该div中的某个位置(并且不会删除已经出现的其他图像)

编辑:

我得到的是:

        function placeimage(){
            $('#div').append('<img src="fooi.png" alt="image" id="'. Math.floor(Math.random()*55) .'" onclick="doclick(this.id);">');
            setTimeout(placeimage, 2000);
        }

        placeimage();
函数placeimage(){
$('#div')。附加('');
设置超时(placeimage,2000);
}
placeimage();
使用:

函数placeimage(){
$div=$(“#div”);
$div.css('position','absolute');
id='ranimg'+数学地板(Math.random()*55);
左=Math.floor(Math.random()*parseInt($div.innerWidth());
top=Math.floor(Math.random()*parseInt($div.innerHeight());
$div.append(“”);
$img=$(“#”+id);
$img.css('top',left+'px');
$img.css('left',top+'px');
$img.show();
setInterval(函数(){placeimage();},15000);
}
placeimage();
先写一些css

#div img {position: relative; float: left }
下面是如何描述的

function placeimage(){
        var t = $('<img src="fooi.png" alt="image" id="' +  Math.floor(Math.random()*55)  + '" onclick="doclick(this.id);">');
        $('#div').append(t);
        t.css('left', Math.floor(Math.random()*(400 - t.width())));
        t.css('top', Math.floor(Math.random()*(250 - t.height())));
        setTimeout(placeimage, 2000);
    }

    placeimage();
函数placeimage(){
变量t=$('');
$('#div')。追加(t);
t、 css('left',Math.floor(Math.random()*(400-t.width()));
t、 css('top',Math.floor(Math.random()*(250-t.height()));
设置超时(placeimage,2000);
}
placeimage();

您需要提出特定的问题,以显示您尝试过的代码。毛毯我怎么做这不是这个网站的工作方式请编辑你的question@mcgrailm你说具体是什么意思?我真的无法更好地解释它,我只想在div.show中的某个地方生成一个包含fooi.png的标记,显示您已经尝试或正在尝试做什么,以及您遇到的问题。一个好的起点是使用timer@mcgrailm我已经用我已经得到的编辑了我的文章。现在我需要在div中的任意位置生成img标记。。。怎么做?好的,这也可以创建一个超时,但我仍然想在div内的一个随机点上获取我的图像!?!这个答案并没有真正的帮助…@是的,我一去做演示就发现了这一点。请参见编辑和链接。注意,我在演示中使用了我自己的gravatar和15秒。
function placeimage(){
        var t = $('<img src="fooi.png" alt="image" id="' +  Math.floor(Math.random()*55)  + '" onclick="doclick(this.id);">');
        $('#div').append(t);
        t.css('left', Math.floor(Math.random()*(400 - t.width())));
        t.css('top', Math.floor(Math.random()*(250 - t.height())));
        setTimeout(placeimage, 2000);
    }

    placeimage();