Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.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 随机更改图像顶部不同div的不透明度级别_Javascript_Html_Css - Fatal编程技术网

Javascript 随机更改图像顶部不同div的不透明度级别

Javascript 随机更改图像顶部不同div的不透明度级别,javascript,html,css,Javascript,Html,Css,我试图改变不透明度水平随机不同的div覆盖一个固定的背景图像,但没有运气到目前为止。。我已经链接了下面的代码,这是我能得到的最接近的。。有没有更好的方法做这件事。。?(事先抱歉,伙计们,我在这方面是个新手.) 我希望它像这个网站一样工作 (函数fadeInDiv(){ var divs=$('.fade'); var elem=divs.eq(Math.floor(Math.random()*divs.length)); 如果(!elem.is(':visible')){ elem.prev(

我试图改变不透明度水平随机不同的div覆盖一个固定的背景图像,但没有运气到目前为止。。我已经链接了下面的代码,这是我能得到的最接近的。。有没有更好的方法做这件事。。?(事先抱歉,伙计们,我在这方面是个新手.)

我希望它像这个网站一样工作

(函数fadeInDiv(){
var divs=$('.fade');
var elem=divs.eq(Math.floor(Math.random()*divs.length));
如果(!elem.is(':visible')){
elem.prev().remove();
动画元素({
不透明度:1
},Math.floor(Math.random()*1000),fadeInDiv);
}否则{
动画元素({
不透明度:(Math.random()*1)
},Math.floor(Math.random()*1000),函数(){
前元素

您的解决方案非常接近一个好结果

然而,它缺乏“动态性”。我已经修改了您的代码,以增加更平滑和可伸缩性

//数组洗牌方法
函数洗牌(数组){
var currentIndex=array.length,
时间值,随机指数;
//虽然还有一些元素需要洗牌。。。
而(0!==currentIndex){
//选择剩余的元素。。。
randomIndex=Math.floor(Math.random()*currentIndex);
currentIndex-=1;
//并将其与当前元素交换。
临时值=数组[currentIndex];
数组[currentIndex]=数组[randomIndex];
数组[randomIndex]=临时值;
}
返回数组;
}
(功能fadeInDiv(){
var divs=$('.fade'),
divLength=divs.length,
arrayToFade=[];
//填充数组
对于(i=0;i
html,
身体{
保证金:0;
填充:0;
最小高度:100vh;
最小宽度:100vw;
}
.缩略图{
宽度:100%;
高度:100vh;
浮动:左;
位置:相对位置;
背景图片:url(http://www.cecchi.net/public/images/3/header-cecchi-headerimage.jpg);
背景尺寸:封面;
}
.覆盖{
排名:0;
左:0;
右:0;
底部:0;
位置:绝对位置;
}
.褪色{
背景:rgba(168,99,37,4);
显示:块;
浮动:左;
宽度:33.333%;
身高:50%;
}

谢谢@Pierre Burton那好多了!:D天才~