瀏覽代碼

Add random picking on specific transitions or animations

Jay Salvat 10 年之前
父節點
當前提交
b493cbff71
共有 4 個文件被更改,包括 34 次插入10 次删除
  1. 17 5
      dist/vegas.js
  2. 0 0
      dist/vegas.min.js
  3. 0 0
      dist/vegas.min.js.map
  4. 17 5
      src/vegas.js

+ 17 - 5
dist/vegas.js

@@ -197,6 +197,10 @@
             }
         },
 
+        _random: function (array) {
+            return array[Math.floor(Math.random() * (array.length - 1))];
+        },
+
         _slideShow: function () {
             var self = this;
 
@@ -287,7 +291,7 @@
                 align   = this._options('align'),
                 valign  = this._options('valign'),
                 color   = this._options('color') || this.$elmt.css('background-color'),
-                cover    = this._options('cover') ? 'cover' : 'contain',
+                cover   = this._options('cover') ? 'cover' : 'contain',
                 total   = $slides.length,
                 video,
                 img;
@@ -297,8 +301,12 @@
                 animation          = this._options('animation' ),
                 animationDuration  = this._options('animationDuration');
 
-            if (transition === 'random') {
-                transition = this.transitions[Math.floor(Math.random() * (this.transitions.length - 1))];
+            if (transition === 'random' || transition instanceof Array) {
+                if (transition instanceof Array) {
+                    transition = this._random(transition);
+                } else {
+                    transition = this._random(this.transitions);
+                }
             }
 
             if (transition && transition !== 'none' && this.transitions.indexOf(transition) < 0) {
@@ -309,8 +317,12 @@
                 transitionDuration = delay;
             }
 
-            if (animation === 'random') {
-                animation = this.animations[Math.floor(Math.random() * (this.animations.length - 1))];
+            if (animation === 'random' || animation instanceof Array) {
+                if (animation instanceof Array) {
+                    animation = this._random(animation);
+                } else {
+                    animation = this._random(this.animations);
+                }
             }
 
             if (animation && animation !== 'none' && this.animations.indexOf(animation) < 0) {

File diff suppressed because it is too large
+ 0 - 0
dist/vegas.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/vegas.min.js.map


+ 17 - 5
src/vegas.js

@@ -188,6 +188,10 @@
             }
         },
 
+        _random: function (array) {
+            return array[Math.floor(Math.random() * (array.length - 1))];
+        },
+
         _slideShow: function () {
             var self = this;
 
@@ -278,7 +282,7 @@
                 align   = this._options('align'),
                 valign  = this._options('valign'),
                 color   = this._options('color') || this.$elmt.css('background-color'),
-                cover    = this._options('cover') ? 'cover' : 'contain',
+                cover   = this._options('cover') ? 'cover' : 'contain',
                 total   = $slides.length,
                 video,
                 img;
@@ -288,8 +292,12 @@
                 animation          = this._options('animation' ),
                 animationDuration  = this._options('animationDuration');
 
-            if (transition === 'random') {
-                transition = this.transitions[Math.floor(Math.random() * (this.transitions.length - 1))];
+            if (transition === 'random' || transition instanceof Array) {
+                if (transition instanceof Array) {
+                    transition = this._random(transition);
+                } else {
+                    transition = this._random(this.transitions);
+                }
             }
 
             if (transition && transition !== 'none' && this.transitions.indexOf(transition) < 0) {
@@ -300,8 +308,12 @@
                 transitionDuration = delay;
             }
 
-            if (animation === 'random') {
-                animation = this.animations[Math.floor(Math.random() * (this.animations.length - 1))];
+            if (animation === 'random' || animation instanceof Array) {
+                if (animation instanceof Array) {
+                    animation = this._random(animation);
+                } else {
+                    animation = this._random(this.animations);
+                }
             }
 
             if (animation && animation !== 'none' && this.animations.indexOf(animation) < 0) {

Some files were not shown because too many files changed in this diff