【问题标题】:Spread images based on random numbers基于随机数传播图像
【发布时间】:2014-04-11 13:32:45
【问题描述】:

我想根据用户在插件中提供的 X 和 Y 值在整个页面中传播我的图像。目前,它采用整组图像并将其作为条形放置在我获得的最新两个坐标上。但我希望图像随机分布在用户定义的区域内。

flickrJSONParse: function (response) {
            $.each(response, function (item, i) {
                $.each(i.photo, function (photoItem, ItemI) {
                    var URL = "http://farm" + ItemI.farm + ".staticflickr.com/" + ItemI.server + "/" + ItemI.id + "_" + ItemI.secret + "_b.jpg";
                    var generated = $selector.append("<div class='item'><img class='image' src=" + URL + " alt=" + ItemI.title + " />" + "<a href='#' class='overlay'><h3 class='title'>" + ItemI.title + "</h3></a>" + "</div>");
                    generated.css({
                        position: "absolute",
                        left: Math.floor(Math.random()*(settings.Xmax-settings.Xmin+1)+settings.Xmin),
                        top: Math.floor(Math.random()*(settings.Ymax-settings.Ymin+1)+settings.Ymin)
                    })
                });
            });
        }

上面是我的代码,下面是我的 CSS:

html, body, *{
    margin: 0;
    padding: 0;
    border: 0;
    font-family: sans-serif;
}
html{
    overflow-y: scroll;
}

.item{
    position: relative;
    float: left;
    line-height: 1em;
    display: inline;
    width: 100%;
    height: 100%;
}
.image{
    margin: 0;
    width: 20%;
    display: block;
}
.image:after{
    clear: both;
}
.overlay{
    position: absolute;
    top: 0;
    left: 0;
    width: 20%;
    height: 100%;
    background-color: rgba(0, 0, 0, .7);
    text-decoration: none;
    color: #FFF;
    display: none;
}
.overlay .title{
    font-size: 1em;
    text-align: center;
}
.item:hover .overlay{
    display: block;
}

这是 jsFiddle:jsFiddle

【问题讨论】:

    标签: jquery html css jquery-plugins


    【解决方案1】:

    我很确定 .append() 返回原始对象,而不是您附加到它的那个。所以可能类似于generated.find('#'+newItemId).css(/*css stuff*/);,其中newItemId 是您刚刚插入的itemid 属性。

    【讨论】:

    • 但是,我想随机化每个图像,而不是最新的?
    • 是的,就是这样!谢谢!我是否也可以进行一种设置来检查它们是否重叠,然后腾出更多空间?
    • 你必须改变随机放置的方式,但我相信这是可能的。
    猜你喜欢
    • 2022-07-10
    • 2013-03-06
    • 1970-01-01
    • 2014-10-10
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多