Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery Use Random Attribute

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #154908
    Steven Morgan
    Participant

    I have this function, and I want to know how to use a different one every time a user comes to the page. For instance choose random transition values like slidein, slidedown, slideup, etc.

    $('element_to_pop_up').bPopup({
    speed: 650,
    transition: 'slideIn'
    });
    

    Same way with a color element:

    $('element').css("background", "black");
    

    Get a random value for those. Do I have to create an array and have it select a random value? I’m not sure of the exact syntax on that

    #154918
    TheDoc
    Member
    var transitions = [
        "slideIn",
        "slideDown",
        "slideUp"
    ];
    
    var randomTransition = transitions[Math.floor(Math.random() * transitions.length)];
    
    $('element_to_pop_up').bPopup({
        speed: 650,
        transition: randomTransition
    });
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.