简体   繁体   English

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

[英]Jquery css z-index Math.random() not working

I'm trying to create simple polaroid-style gallery. 我正在尝试创建简单的宝丽来风格画廊。 I'm doing okay with random positioning and css-transition rotation, but when it comes to randoming z-index, i'm failing (i need it, because it's ugly when the same image lies above all other whenever you shuffling) 我对随机定位和css-transition旋转做得很好,但是当涉及随机z-index时,我失败了(我需要它,因为当你洗牌时同一个图像高于其他所有图像时它很难看)

http://jsfiddle.net/PWHAL/1/ - here is jsfiddle, i commented lines with z-index random http://jsfiddle.net/PWHAL/1/ - 这里是jsfiddle,我评论了z-index随机的行

Best case for testing is grouping button 最好的测试案例是分组按钮

IPORTANT NOTE: code runnable only on webkit, because i was testing css transition properties only for this engine Code example: 重要说明:代码只能在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
        });
    });
});

This stuff even supposed to work? 这东西甚至应该工作?

您是否尝试确保随机数是整数?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM