Forums

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

Home Forums JavaScript Convert JQuery function to pure JS?

  • This topic is empty.
Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #190860
    Paulie_D
    Member

    I think where we are headed is 6 colors….one for the site background and 5 more (1 for each of the list items).

    What we then need, on reading back. is to set a random page background from the list and then loop thorough each of the list items setting an individual background color that hasn’t already been used).

    Basically,

    Set page background randomly from array
    Remove selected color from array

    Set first li background color randomly from new array
    Remove selected color from array

    Set next li background color randomly from new smaller array
    Remove selected color from array

    Repeat.

    Do I have that right?

    #191032
    codemasters
    Participant

    http://jsfiddle.net/codemasters14/2nzoxu1n/

    1) This what i want .
    2) Is there a better way of doing it .
    3) the colors are repeating so how do i check for that

    #191133
    codemasters
    Participant

    can someone help me on this

    #191160
    Paulie_D
    Member

    Updated to automatically set all background colors of the list items present. Repeating if there are more of them than there are colors.

    If the “feature” Rosette thingy still worked I’d award this for going above any beyond.

    All you get now is a ‘yellow’ shading….s’not the same.

    #191243
    Paulie_D
    Member

    I can’t resist posting this bit where the identifiers for each list item wouldn’t even be needed :

    Could you post a forked Codepen with this last piece of the puzzle n place…then I think we can put this one to bed.

    Excellent work and went over and above the level of support usually seen.

    #191352
    LewisCowles1986
    Participant

    entertainment…
    Shuffling the array was a nice touch, and IMHO the only way I could see it feasibly working in a real system because of the control needed and the uncertain nature of the output without it.

    So

    • shuffle pre-existing array of CSS-valid color strings
    • loop over a querySelectorAll (array) of matching items

    • set colour based upon modulo of index

    Enjoy!

    My take on all this
    http://codepen.io/Lewiscowles1986/pen/zxBbGz

    #192353
    codemasters
    Participant

    ok thanks guys will check this an will need to understand thanks a ton

    #192355
    codemasters
    Participant

    Shikkediel was not able to follow the code can u write in comments as what is happening where as i am a beginer egg// here i am changing the color

Viewing 8 posts - 16 through 23 (of 23 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.