Forums

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

Home Forums JavaScript Dark/Light color switch

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 45 total)
  • Author
    Posts
  • #260659
    Funkaholik
    Participant

    Hi y’all
    Need some help with button-trigger-color-switcher
    is there a way to target a specific colors (or at least two) to switch them for all elements that has those colors.
    toggle + button for each move like hit a dark (switch to dark) hit a light (switch to normal)

    #260664
    Shikkediel
    Participant

    You won’t be able to switch colour on the pseudo elements (if that was the idea)…

    Here’s some generic code, I’d probably choose the filter function for it:

    $('button').click(function() {
    
      if ($(this).index() == 1) {
    
        $('.line').filter(function() {
    
          if ($(this).css('background-color') == 'rgb(241, 74, 255)') return this;
        })
        .css('background-color', 'black');
      }
    });
    

    Edit – actually, you can with a bit of CSS trickery:

    https://codepen.io/anon/pen/QqvWrr

    #260665
    Funkaholik
    Participant

    actually i just want it to change white to black & black to white
    to keep all other colors same, like youtube does nowadays

    idea is to target color in css and change it for all elements that has that color

    i don’t know why i did that pen .. )

    #260667
    Shikkediel
    Participant

    I thought the new layout was utterly bland so I immediately went back to old YT. Dunno what they’re doing with colour switching. The essential most inner function above should still do a good job of selecting the elements.

    #260731
    Funkaholik
    Participant

    you’re targeting only background-color there
    is it possible to target background & color at the same time here

    #260740
    Shikkediel
    Participant

    Target how? What should change in response to each button exactly?

    #260769
    Funkaholik
    Participant

    basically .. target background-color and color of all elements and switch them colors
    usually background is transparent or #fff and color #333 so it’ll be great to be able to switch them by toogle

    #260773
    Shikkediel
    Participant

    So how many types of elements are there, 2 or 4?

    With the term “targeting” I’m not sure whether you mean for selection or adjustment…

    #260793
    Shikkediel
    Participant

    How about you buzz off, idiot spammer.

    #260794
    Funkaholik
    Participant

    his website not even workin’ ))

    switch background-color & color of all elements .. is it possible?

    #260799
    Atelierbram
    Participant

    Searching for “css style switcher” gives results like these: sitepoint.com/creating-simple-style-switcher/
    @funkaholic Would that work for you?

    #261002
    Funkaholik
    Participant

    Actually i come up with the idea (saw somewhere) that makes it very simple=))
    add class to body and switch them with button (toggle classes)
    .light bg: #fff color: #333 & .dark bg:#333 color #fff

    the only problem for me right now is that
    i’m using also text-fill-color and stroke for certain elements
    and i have no idea how to change them also with that same button

    plus text-fill-color overwrites color so there is also conflicts((
    And still i think the easiest way will be change colors with js
    kinda find all #333 and change to #fff & find all #fff and change to #333

    #261007
    Funkaholik
    Participant

    Thanx, your example was on point
    the only thing is i want to use button to switch two styles
    and i have no idea how to rewrite js for a button not for select with dropdowns

    #261053
    Funkaholik
    Participant

    here’s a pen
    so you’ll know what i mean
    if there is a solution for that or we can change css colors without targeting properties of css
    but just switch colors in js .. let me know

    #261058
    Shikkediel
    Participant

    I tried to post a reply but apparently edited too many times. My keyboard when haywire, outputting the wrong characters…

    Anyway, the second part of your existing code could be reduced to this:

    $('#theme').toggleClass('light dark');
    

    I’ll have to take another look at what you’re trying the do exactly otherwise.

Viewing 15 posts - 1 through 15 (of 45 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.