123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- (function($) {
- $.fn.menucloud = function(settings)
- {
- settings = $.extend({}, $.fn.menucloud.defaults, settings);
-
- $('ul', this).css({
- 'position':'relative',
- 'width':'100%',
- 'height':'100%',
- 'padding':0
- })
-
- $('li', this).css({'top':"-100px", 'left':'-100px'}).each(function(i,e){
- var $li = $(e);
- $li.css({
- // 'border':'1px solid red',
- 'position':'absolute'
- });
-
- var $prt = $li.parent('ul.menu');
- // $.log('li', $li);
- // $.log('$this | width = '+$li.width()+' | height = '+$li.height());
- // $.log('$prt | width = '+$prt.width()+' | height = '+$prt.height());
-
- function _testPos(t){
- var isok = true;
- $li.siblings().each(function(j, sib){
- $sib = $(sib);
- // var pos = $sib.position();
- // $.log('pos',pos);
- var css_sib_top = $sib.css('top');
- // $.log('css_sib_top.match("/em/") = '+css_sib_top.search('em'));
- var sib_top = css_sib_top.search('em') >= 0 ? parseFloat(css_sib_top)/settings.q : parseFloat(css_sib_top);
-
- // $.log('sib_top = '+sib_top);
- // $.log('t = '+t+' | sib_top = '+sib_top);
- // $.log('Math.abs(top-sib_top) = '+Math.abs(top-sib_top));
-
- if(Math.abs(t-sib_top) < 35){
- isok = false;
- return false;
- };
-
- });
-
- return isok;
- };
-
- var isPosOK = false;
- var limit = 0;
- while(!isPosOK && limit < 10){
- var top = (Math.round(Math.random()*(($prt.height()-settings.margin.t-settings.margin.b)-$li.height()))+settings.margin.t);
- var left = (Math.round(Math.random()*(($prt.width()-settings.margin.l-settings.margin.r)-$li.width()))+settings.margin.l);
- isPosOK = _testPos(top);
- // $.log('isPosOK = '+isPosOK);
- limit = limit+1;
- }
-
- $li.css({
- 'top':(top*settings.q)+'em',
- 'left':(left*settings.q)+'em'
- });
-
- // $.log('- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ');
-
- });
-
- return this;
- }
- $.fn.menucloud.defaults = {
- q:0.063,
- margin : {t:0,r:0,b:0,l:0}
- };
- })(jQuery);
|