Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 Jquery css z-index Math.random()不起作用_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript Jquery css z-index Math.random()不起作用

Javascript Jquery css z-index Math.random()不起作用,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我试图创建简单的宝丽来风格画廊。我在随机定位和css转换旋转方面做得不错,但在随机z索引方面,我失败了(我需要它,因为当你洗牌时,同一个图像凌驾于所有其他图像之上时,这很难看) -这是JSFIDLE,我用z-index random注释了行 测试的最佳情况是分组按钮 IPORTANT注意:代码只能在webkit上运行,因为我只测试了这个引擎的css转换属性 代码示例: var realWidth = $(document).width(); var realHeight = $(document

我试图创建简单的宝丽来风格画廊。我在随机定位和css转换旋转方面做得不错,但在随机z索引方面,我失败了(我需要它,因为当你洗牌时,同一个图像凌驾于所有其他图像之上时,这很难看)

-这是JSFIDLE,我用z-index random注释了行

测试的最佳情况是分组按钮

IPORTANT注意:代码只能在webkit上运行,因为我只测试了这个引擎的css转换属性 代码示例:

var realWidth = $(document).width();
var realHeight = $(document).height();
$("#polaroidButton").click(function() { 
    $(".hiddenh1").hide();
    $(".picCont").each(function() {
        $(this).css({
            '-webkit-transform' : 'rotate(' +Math.random()*360 +'deg)', 
            "left" : Math.random()*(realWidth-400),
            'top' : Math.random()*(realHeight-440),
            'z-index' : Math.random()*100 + 51
        });
    });
});

这些东西甚至应该起作用吗?

你有没有尝试确保随机数是一个整数

'z-index' : parseInt(Math.random()*100, 10) + 51

z指数有什么问题?我再点击10次“Groups pls”按钮似乎没问题,如果你得到div的1/2高于3,4/5高于6或7/8高于9,那么我的浏览器就有问题了=/添加parseInt,就像Arjun对你所有的z-inde实例所说的那样,它可以在localpc上工作,没有什么新的:(很抱歉,伙计,在测试中漏掉了一行。使用parseInt,所有工作都非常完美,谢谢!