seanmoo

about random color of backgroundcolor

Recommended Posts

i want to set random backgroundcolor of  the animate  elements, but still not works,  

in the following code,i tried to test several properties  "left"、"top" and "skewY" "backgroundColor",why "left" "top" is regular working,

if  set "backgroundColor"  value to colors arrary  ,it can regular working ,  but set to an anonymous funtion will not work. the "skewY" is same issue,

it confused me , the anonymous funtion return a colors arrary too, why not work.

var colors = ["#164","#350","#350","#088","#254","#401","#306","#209","#005","#987","#614","#767","#406","#909","#201","#405","#806","#558"];
var tween = new TimelineLite();
var obj = $(".dot-test");
tween.add(TweenMax.staggerFrom(obj, 2, {
    cycle: {
        skewY: ["42deg", "242deg", "12deg", "92deg", "256deg", "310deg", "48deg", "122deg", "162deg", "142deg", "77deg"],
//     backgroundColor : colors,

        backgroundColor:function(){
              var m = new Array();
            for (var i = 0; i < 80; i++) {
                m.push("#"+ Math.floor((Math.random() * 10))+ Math.floor((Math.random() * 10))+Math.floor((Math.random() * 10))); // to construct a color arrary.
            }
            console.info(m);
            return m;
        },

        left: function () {
            var m = [];
            for (var i = 0; i < 80; i++) {
                m.push(Math.random() * 10000 * (Math.random() > 0.5 ? -1 : 1));
            }
            return m;
        },
        top: function () {
            var m = [];
            for (var i = 0; i < 80; i++) {
                m.push(Math.random() * 5000 * (Math.random() > 0.5 ? -1 : 1));
            }
            return m;
        },

        autoAlpha: [0],
     },
    yoyo: true,
    ease: Power4.easeOut
 },0.1));

 
thanks for come in to see my iusse.

 

Share this post


Link to post
Share on other sites

You need to run your backgroundColor function first to generate the array.

 

backgroundColor: (function(){
  var m = new Array();
  for (var i = 0; i < 80; i++) {
    m.push("#"+ Math.floor((Math.random() * 10))+ Math.floor((Math.random() * 10))+Math.floor((Math.random() * 10))); // to construct a color arrary.
  }
  return m;
})(),

 

  • Like 2

Share this post


Link to post
Share on other sites
44 minutes ago, OSUblake said:

You need to run your backgroundColor function first to generate the array.

 


backgroundColor: (function(){
  var m = new Array();
  for (var i = 0; i < 80; i++) {
    m.push("#"+ Math.floor((Math.random() * 10))+ Math.floor((Math.random() * 10))+Math.floor((Math.random() * 10))); // to construct a color arrary.
  }
  return m;
})(),

 

i got it,  thank you so much . my issue have resloved

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.