-1

I had this working awhile ago, I had figured it out.

But I forgot to save it.

I do know it was hard for me to figure out, but I don’t remember what I did.

I figured this part out. https://jsfiddle.net/39ph4bvs/9/

I am doing something wrong here, but I can't seem to wrap my head around what I am doing incorrectly.

I can't wrap my head around how to fix the CSS.

My head hurts from trying to figure out how to do this.

It's only the CSS that is messed up.

All I am doing is adding custom css selectors which is giving me a hard time.

Ignore the videos, it's only the custom css selectors I am trying to get working. The css selectors have nothing to do with the videos. I don't need help with videos, I need help with implementing the custom css selectors.

I think this part I have fine.

This part is GOOD

.bg1 {
  --color-a: linear-gradient(120deg, #155799, #159957);
}

.bg2 {
  --color-b: linear-gradient(0deg, #522db8 0%, #1c7ce0 100%);
}

.bg3 {
  --color-c: linear-gradient(45deg, #102eff, #d2379b);
}

.bg4 {
  --color-d: linear-gradient(90deg, #360033 30%, #0b8793 100%);
}

.bg5 {
  --color-e: linear-gradient(115deg, #0a0e88, #00b1ce);

}

.bg6 {
  --color-f: linear-gradient(0deg, #522db8 0%, #1c7ce0 100%);
}

.bg7 {
  --color-g: linear-gradient(0deg, #522db8 0%, #1c7ce0 100%);
}

.bg8 {
  --color-h: linear-gradient(0deg, #522db8 0%, #1c7ce0 100%);
}

.bg9 {
  --color-i: linear-gradient(0deg, #522db8 0%, #1c7ce0 100%);
}

I got stuck here:

I have no idea why my head is confused on how this is done.

WRONG

body {
  background-image:
    linear-gradient(var(--color-a)),
    linear-gradient(var(--color-b)),
    linear-gradient(var(--color-c)),
    linear-gradient(var(--color-d)),
    linear-gradient(var(--color-e)),
    linear-gradient(var(--color-f)),
    linear-gradient(var(--color-g)),
    linear-gradient(var(--color-h)),
    linear-gradient(var(--color-i));
  background-repeat: no-repeat;
}

That part there is entirly wrong. I don't know how to fix it. There is a way for it to be written, I don't know how to do it.

Here was my second attempt: https://jsfiddle.net/qsb2kvca/2/

I have a working version here and I am still confused. https://jsfiddle.net/g9h4xLsv/

I have no idea why my head can’t figure this out.

WRONG

body {
  background-image:
    (var(--color-a)),
    (var(--color-b)),
    (var(--color-c)),
    (var(--color-d)),
    (var(--color-e)),
    (var(--color-f)),
    (var(--color-g)),
    (var(--color-h)),
    (var(--color-i));
  background-repeat: no-repeat;
}

That part there is entirly wrong. I don't know how to fix it. There is a way for it to be written, I don't know how to do it.

Here was my 3rd attempt: https://jsfiddle.net/8b0msnkL/3/

WRONG

body {
  background-image:
    linear-gradient(var(--color-a), var(--color-a)),
    linear-gradient(var(--color-b), var(--color-b)),
    linear-gradient(var(--color-c), var(--color-c)),
    linear-gradient(var(--color-d), var(--color-d)),
    linear-gradient(var(--color-e), var(--color-e)),
    linear-gradient(var(--color-f), var(--color-f)),
    linear-gradient(var(--color-g), var(--color-g)),
    linear-gradient(var(--color-h), var(--color-h)),
    linear-gradient(var(--color-i), var(--color-i));
  background-repeat: no-repeat;
}

That part there is entirly wrong. I don't know how to fix it. There is a way for it to be written, I don't know how to do it.

I tried reducing the code down to 1 line here:

https://jsfiddle.net/8b0msnkL/6/

That does not seem to be helping.

WRONG

.bg1 {
  --color-a: linear-gradient(120deg, #155799, #159957);
}

body {
  background-image:
    linear-gradient(var(--color-a), var(--color-a));
  background-repeat: no-repeat;
}

That part there is entirly wrong. I don't know how to fix it. There is a way for it to be written, I don't know how to do it.

Eve Ninnall
  • 1
  • 3
  • 20
  • What `this` is supposed to be ? And why they are the videos for all your examples? – Mister Jojo Mar 29 '22 at 02:05
  • Ignore the videos, it's only the custom css selectors I am trying to get working. The css selectors have nothing to do with the videos. I don't need help with videos, I need help with implementing the custom css selectors. – Eve Ninnall Mar 29 '22 at 02:22
  • If you want me to delete the videos, I delete them, but I am still left with the same issue of implementing the custom css selectors. – Eve Ninnall Mar 29 '22 at 02:27
  • What `this` is supposed to be (in your sentence : "" had **this** working awhile ago"" ) ? I have no idea of what you are lookink for. did you read : https://stackoverflow.com/help/how-to-ask **and** https://stackoverflow.com/help/minimal-reproducible-example ... https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/ – Mister Jojo Mar 29 '22 at 02:37
  • Maybe another person will be able to help me. As you can see, the custom css selectors are not working. I am having serious trouble setting up the css selectors. – Eve Ninnall Mar 29 '22 at 02:39
  • maybe by asking your question better, several other people would have already answered you... – Mister Jojo Mar 29 '22 at 02:41
  • The only trouble with the code I am having issues with is the CSS. – Eve Ninnall Mar 29 '22 at 02:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243399/discussion-between-erica-levine-and-mister-jojo). – Eve Ninnall Mar 29 '22 at 02:43
  • It doesn't change the fact that your question is poorly worded. – Mister Jojo Mar 29 '22 at 02:51
  • I do not know the right words other than, the css selectors as they are currently written are wrong. body { background-image: linear-gradient(var(--color-a), var(--color-a)), – Eve Ninnall Mar 29 '22 at 02:53
  • That is the part that is wrong. – Eve Ninnall Mar 29 '22 at 03:00
  • `var(--color-a)` will resolve to the value `linear-gradient(120deg, #155799, #159957)`. If you do `linear-gradient(var(--color-a))` it will resolve to `linear-gradient(linear-gradient(120deg, #155799, #159957))` which is invalid, same with `background-image: (var(--color-a))`, the parentheses make this invalid, what you want seems to simply be `background-image: var(--color-a), var(--color-b)`. – Kaiido Mar 29 '22 at 03:18
  • Can you show me it working in the code please? I am not able to figure that out. – Eve Ninnall Mar 29 '22 at 03:23

1 Answers1

1

that ?

:root {
  --color-a: linear-gradient(120deg, #155799,     #159957      );
  --color-b: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-c: linear-gradient( 45deg, #102eff,     #d2379b      );
  --color-d: linear-gradient( 90deg, #360033 30%, #0b8793 100% );
  --color-e: linear-gradient(115deg, #0a0e88,     #00b1ce      );
  --color-f: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-g: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-h: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-i: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  }
body {
  background-image: var(--color-a);
  }

PO : Can you show me it working in the code?

(()=> //  === randomBackground == IIFE  
  {
  let colorOn = colorN = 0;
  setInterval(() =>
    {
    while (colorOn === colorN)
      colorN = Math.floor(Math.random() * 6);
    colorOn = colorN
    document.body.style.setProperty('--colorX', `var(--color-${colorOn})`)
    }
    , 5000);  // change backGround every 5 seconds
  }
 )()
:root {
  --color-0: linear-gradient(120deg, #155799,     #159957      );
  --color-1: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-2: linear-gradient( 45deg, #102eff,     #d2379b      );
  --color-3: linear-gradient( 90deg, #360033 30%, #0b8793 100% );
  --color-4: linear-gradient(115deg, #0a0e88,     #00b1ce      );
  --color-5: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% );
  --color-6: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% ); /* same as 5 */
  --color-7: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% ); /* same as 5 */
  --color-8: linear-gradient(  0deg, #522db8  0%, #1c7ce0 100% ); /* same as 5 */

  --colorX: var(--color-0);
  }
body {
  background-image : var(--colorX);
  height           : 100vh;
  margin           : 0;
  }

with no setInterval

let colorRandom = 'var(--color-' + Math.floor(Math.random() *9) + ')'
document.body.style.setProperty('--colorX',colorRandom)
Mister Jojo
  • 20,093
  • 6
  • 21
  • 40