Home › Forums › JavaScript › Convert JQuery function to pure JS?
- This topic is empty.
-
AuthorPosts
-
December 15, 2014 at 9:26 am #190860Paulie_DMember
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 arraySet first li background color randomly from new array
Remove selected color from arraySet next li background color randomly from new smaller array
Remove selected color from arrayRepeat.
Do I have that right?
December 17, 2014 at 2:24 am #191032codemastersParticipanthttp://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 thatDecember 18, 2014 at 3:10 am #191133codemastersParticipantcan someone help me on this
December 18, 2014 at 9:20 am #191160Paulie_DMemberUpdated 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.
December 19, 2014 at 6:42 am #191243Paulie_DMemberI 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.
December 21, 2014 at 4:44 am #191352LewisCowles1986Participantentertainment…
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/zxBbGzJanuary 6, 2015 at 1:43 am #192353codemastersParticipantok thanks guys will check this an will need to understand thanks a ton
January 6, 2015 at 2:47 am #192355codemastersParticipantShikkediel 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
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.