animate properties top-bottom right-left chosen randomly
I am trying to animate random properties on the x and y's
//generates a random right or left
var randX = function(){
var randXresult;
var startWith = Math.random()*5;
if(startWith>3){
randXresult="right";
开发者_开发问答 }
else{randXresult="left"}
return randXresult
}
//generates a random top or bottom
var randY = function(){
var randYresult;
var startWith = Math.random()*5;
if(startWith>3){
randYresult="top";
}
else{randYresult="bottom"}
return randYresult
}
//generates a random number
var getRandomNo = function(){
var randomNo = Math.random()*9999;
return randomNo
}
// i am only showing the first .toggle() function
$(".innerColContainer div a").toggle(
function(){
$(this).parent().siblings().each(function(i){
Xrandom = randX()
Yrandom = randY()
alert(Xrandom+Yrandom) //this alerts the results i am looking for
//but how do i get the results in the .animate()
$(this).animate({ Xrandom:getRandomNo(), Yrandom:getRandomNo()}, 1400);
});
So my question is: How could i get that random
"top
" or "right
" inside the .animate()
since alert(Xrandom+Yrandom)
has the value i am looking for.
var props = {};
props[Xrandom]=getRandomNo();
props[Yrandom]=getRandomNo();
$(this).animate(props, 1400);
If I'm reading correctly, "getRandomNo()" will not return an evenly distributed random number (which is usually what you want, but maybe it isn't in this case...only you can tell what you want it to do). 80% of the results will be evenly distributed between 5000 and 12999, and 20% of the results will be evenly distributed between 8000 and 9999. 8000-9999 will be twice as likely a result as 5000-7999 and 10000-12999.
精彩评论