0

I have no visual example to show you, so I will try as hard as I can to make it understandable. - I can compare it with camera flash.

main part of this question is to get answer about functions that I need to use to get to my goal.

I have div that is "base div" for this effect. In "random amount of seconds" (biggest amount can be 6sec) another div must go over the "base div" and stays visible for 0.7sec.

after this effect it repeats again and again and again and with new "random amount of seconds" (biggest amount can be 6sec) between each 0.7sec blink

I know how to get that "blink div" to work (display: none; and when it's time to show I just write display: visible; and display: none;)

but I don't know how to make that "randomization" function...

aainaarz
  • 782
  • 1
  • 7
  • 14

1 Answers1

0

This might answer your "randomization" question: https://stackoverflow.com/a/3594189/353710

function getInterval() {
    var min = 1;
    var max = 6;
    // and the formula is:
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function blink() {
    var newTimeout = getInterval() * 1000;

    console.log('New timeout: ' + newTimeout);

    setTimeout(blink, newTimeout);
}

blink();

I created a fiddle to demonstrate the functionality.

Community
  • 1
  • 1
Nick Stemerdink
  • 1,067
  • 9
  • 22
  • Looks great, but after blink i get same value... seems like it is randomizing only one time and repeat same value. for me it doesn't get new value! after first time! – aainaarz Jul 11 '12 at 12:53