From 560eadbe76cf2cef88e7b4923b13159f08dfcfee Mon Sep 17 00:00:00 2001 From: Vidur Murali Date: Mon, 19 Oct 2015 16:39:20 +0530 Subject: [PATCH] Add option to randomly fall left or right --- README.md | 22 ++++++++++++---------- solitaireVictory.js | 9 +++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 997dd19..854c164 100644 --- a/README.md +++ b/README.md @@ -17,26 +17,28 @@ $('YOUR-CSS-SELECTOR').solitaireVictory(); **With Options:** (*defaults listed*) ``` $('YOUR-CSS-SELECTOR').solitaireVictory({ - + // PHYSICS PROPERTIES g: -3 // Gravity. Must be less than 0; closer to 0 is weaker. - + dt: 20 // Time between frames, in milliseconds. - + bounce: 0.7 // Amount of speed conserved on bounce. - + endVelocity: 20 // If the element is slower than this, it will not bounce. - fallToLeft: false // If set to true, the object will fall to the left instead - // of to the right - - + fallToLeft: false // If set to 'random', the object will have a 50% chance of falling + // left or right + // If set to true, the object will always fall to the left + // If set to false, the object will always fall to the right + + // PAGE CONFIGURATION clear: false // Clears the debris from past victories before starting. - + stagger: 200 // If multiple DOM elements are selected, staggers the starts // by this amount. If set to 0, all elements start at the same time. - + relativeToDocument: false // If set to true, the object will bounce at the bottom of the // document instead of the bottom of the window. This can solve // some issues on longer documents, but looks worse in general. diff --git a/solitaireVictory.js b/solitaireVictory.js index 2701313..3a308aa 100644 --- a/solitaireVictory.js +++ b/solitaireVictory.js @@ -43,7 +43,12 @@ var startFall = function(elem, height, stagger) { var dx = settings.dx || Math.floor((Math.random()*10)) + 5; - if (fallToLeft) { + if (fallToLeft == 'random') { + // Falls left 50% of the time + if (Math.random() >= 0.5) { + dx = -dx; + } + } else if (fallToLeft) { dx = -dx; } var copy = elem.clone(); @@ -71,4 +76,4 @@ }); }; -}( jQuery )); \ No newline at end of file +}( jQuery ));