简体   繁体   中英

rearrange randomly placed divs on click

i have a couple of draggable divs that are placed randomly on the page when loaded

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?

here's the 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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