简体   繁体   English

单击重新排列随机放置的div

[英]rearrange randomly placed divs on click

i have a couple of draggable divs that are placed randomly on the page when loaded 我有几个可拖动的div,在加载时会随机放置在页面上

i want these divs to be rearranged to a pre-specified location on the click of a link, how would i go about doing this? 我希望通过单击链接将这些div重新排列到预先指定的位置,我该怎么做?

here's the jsfiddle: http://jsfiddle.net/BbKsq/7/ 这是jsfiddle: http : //jsfiddle.net/BbKsq/7/

$("#web01,#web02").each(function () {
var randHigh = Math.floor(Math.random() * ($(window).height() - 200));
var randWide = Math.floor(Math.random() * ($(window).width() - 200));
$(this).offset({
    top: randHigh,
    left: randWide

What's the problem if you already generated that much of a code? 如果您已经生成了那么多代码,那会是什么问题?

$('#organize').click(function() { // just add id="organize" somewhere
    $('#web01').offset({
        top: 20, // this is that pre-specified position
        left: 20
    });
});

Am I missing something? 我想念什么吗?

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

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