Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 随机图像,无需单击即可重复_Javascript_Html_Arrays_Image_Random - Fatal编程技术网

Javascript 随机图像,无需单击即可重复

Javascript 随机图像,无需单击即可重复,javascript,html,arrays,image,random,Javascript,Html,Arrays,Image,Random,目前我正在这个网站上工作,我在点击时弹出了一个随机图像,但我的客户觉得有时一个图像重复太多次,所以他们要求我随机但不重复 这是网站链接:(过去的工作部分是它应该工作的地方) 谢谢大家! imageString=[ 'http://fullbleed.life/wp-content/uploads/1.png', 'http://fullbleed.life/wp-content/uploads/2.png', 'http://fullbleed.life/wp-content/uploads/

目前我正在这个网站上工作,我在点击时弹出了一个随机图像,但我的客户觉得有时一个图像重复太多次,所以他们要求我随机但不重复

这是网站链接:(过去的工作部分是它应该工作的地方)

谢谢大家!

imageString=[
'http://fullbleed.life/wp-content/uploads/1.png',
'http://fullbleed.life/wp-content/uploads/2.png',
'http://fullbleed.life/wp-content/uploads/3.png',
'http://fullbleed.life/wp-content/uploads/4.png',
'http://fullbleed.life/wp-content/uploads/5.png',
'http://fullbleed.life/wp-content/uploads/6.png',
'http://fullbleed.life/wp-content/uploads/7.png',
'http://fullbleed.life/wp-content/uploads/8.png',
'http://fullbleed.life/wp-content/uploads/9.png',
'http://fullbleed.life/wp-content/uploads/10.png',
]
姓名=[
“诺德斯特罗姆”,
“塔架”,
“ASP&Hand”,
“法里斯”,
"ARA",,
“traceme”,
"微软",,
“Kozha数字”,
“范德波普”,
“YFF”,
]
函数getRandom(){
var最小值=0
var最大值=10
返回Math.floor(Math.random()*max)
}
$('.pass work').bind('click',函数(事件){
var randNum=getRandom()
var approduct=document.getElementById('rand-images')
var image=document.createElement('img')
image.src=imageString[randNum]
image.style.display='block'
image.style.position='absolute'
image.style.left=event.clientX-280+'px'
image.style.top=event.clientY-280+'px'
APProduct.appendChild(图像)
$(图像).draggable()
event.preventDefault()
})

过去的工作
(单击任意位置,再次单击任意位置)

您可以在阵列中的图像出现后将其删除

imageString=[
'http://fullbleed.life/wp-content/uploads/1.png',
'http://fullbleed.life/wp-content/uploads/2.png',
'http://fullbleed.life/wp-content/uploads/3.png',
'http://fullbleed.life/wp-content/uploads/4.png',
'http://fullbleed.life/wp-content/uploads/5.png',
'http://fullbleed.life/wp-content/uploads/6.png',
'http://fullbleed.life/wp-content/uploads/7.png',
'http://fullbleed.life/wp-content/uploads/8.png',
'http://fullbleed.life/wp-content/uploads/9.png',
'http://fullbleed.life/wp-content/uploads/10.png',
]
姓名=[
“诺德斯特罗姆”,
“塔架”,
“ASP&Hand”,
“法里斯”,
"ARA",,
“traceme”,
"微软",,
“Kozha数字”,
“范德波普”,
“YFF”,
]
var aProduct=document.getElementById('rand-images');
var image=document.createElement('img');
var min=0;
var max=10;
函数getRandom(){
返回Math.floor(Math.random()*max)
}
$('.pass work').bind('click',函数(事件){
如果(最大值>=最小值){
var randNum=getRandom();
image.src=imageString[randNum];
拼接(randNum,1);
马克斯;
image.style.display='block';
image.style.position='绝对';
image.style.left=event.clientX-280+'px';
image.style.top=event.clientY-280+'px';
a产品附录子项(图像);
}
})

过去的工作
(单击任意位置,再次单击任意位置)

如果您在
imageString
中只有一个图像字符串,而您不想将图像显示两次,会发生什么情况?嗯,我真的不明白……您想在用户每次将鼠标悬停在具有
过去工作
类的元素上时显示不同的图像吗?请为您试图解决的具体问题添加更多信息:)hi@luchosrock,我正在尝试使“过去的工作”部分的工作方式与现在一样(每次单击div时都会弹出一个随机图像),但问题是,图像是连续重复的,我不希望它像现在这样不工作:((也许我把它放错了?我应该把代码放在哪里ảmơn bạn nhiề乌哈!它仍然不起作用…现在图像不会显示