0

I have an image slider with text overlayed on it. I want to change the text color to either black or white depending on the theme of the image (light or dark).

I would like to manually specify the theme of the image as I don't want to over-complicate things. So for example it could work like this:

If imagetheme == 'light'
textcolor == #000

...and vice versa.

2
  • 1
    It's very hard to say anything without seeing the code for the slider. Commented Jun 30, 2012 at 15:09
  • I'm using anything slider with a modified style sheet: css-tricks.com/anythingslider-jquery-plugin Commented Jun 30, 2012 at 15:15

2 Answers 2

2

Have a stylesheet that reacts to theme classes placed on the <body> element (e.g. .light). No mess.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't really follow. Basically, I want the image slides to have some sought of tag or property where I can specify the theme of the image (light or dark) and then when a new slide is activated, the text color changes based on the theme inputted.
@Emmanuel: Here's a demo. You can easily apply it to a particular element, as opposed to <body>.
0

I think you have almost written it yourself! I would do..

if ( var imagetheme == 'light' ) {
  var textcolor = '#000';
}
else if { var imagetheme == 'dark' ) {
  var textcolor = '#fff';
}

Or you could write it with Javascript's Ternary operator..

var imagetheme == 'light' ? var textcolor = '#000' : var textcolor = '#fff';

1 Comment

None of those are syntactically valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.