简体   繁体   English

如何组织页面上随机放置的div?

[英]how to organize randomly placed divs on a page?

i have a page which on load places the divs randomly over a page. 我有一个页面,在加载时将div随机放置在页面上。
these divs are also draggable. 这些div也是可拖动的。

i would like to introduce a link on this page that organizes these divs automatically 我想在此页面上引入一个链接,该链接可自动组织这些div

i put all my code on this jsfiddle, although it doesn't seem to work (it does work on my page though) 我把我所有的代码放在这个jsfiddle上,尽管它似乎不起作用(尽管它确实在我的页面上起作用)

http://www.jsfiddle.net/BbKsq/ http://www.jsfiddle.net/BbKsq/

i really don't understand jsfiddle sorry 我真的不明白jsfiddle对不起

hope someone can help me out here, thanks!! 希望有人可以在这里帮助我,谢谢!

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

You should use classes if you want to organize several "similar" divs. 如果要组织多个“相似”的div,则应使用类。 The ID is usually used to differntiate a unique element. 该ID通常用于区分唯一元素。

If you move to that, then you can reorganize all the divs with the same class without much problems, then you can add a button that performs a javscript function that organize some (or all) of the divs with the class that you choose. 如果移至该位置,则可以在没有太大问题的情况下重组具有相同类的所有div,然后可以添加一个执行javscript函数的按钮,该按钮可以将所选的类与部分(或全部)div进行组织。

Hope this helps 希望这可以帮助

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

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