Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Change color of fixed sitetitel/menu when scrolling down page (according to changing row-background)

Change color of fixed sitetitel/menu when scrolling down page (according to changing row-background)

Scheduled Pinned Locked Moved General Discussion
16 Posts 4 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mariusjopen
    Global Moderator
    wrote on Sep 27, 2018, 10:35 AM last edited by
    #6

    Dear @maarschalk
    you can right click on the website to inspect it.

    There you can see all the classes you can use.

    Hope that helps :-)

    Best!

    Marius

    www.mariusjopen.world

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maarschalk
      wrote on Oct 2, 2018, 6:42 AM last edited by
      #7

      Hi Marius,

      for some reason, it does'nt seem to work. Either I'm making a mistake in selecting the right class, or a minor thing is wrong in the code?

      Best,
      Bart

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mariusjopen
        Global Moderator
        wrote on Oct 4, 2018, 3:54 PM last edited by
        #8

        Dear @maarschalk

        I will talk with Armin about that and see what the issue is.

        Best!

        Marius

        www.mariusjopen.world

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mariusjopen
          Global Moderator
          wrote on Oct 12, 2018, 8:50 AM last edited by
          #9

          Dear @maarschalk

          I debugged the code and it works.

          You need to give a row the class blackrow.

          <script>
              var offset = 50;
              var $blackRows;
              var $nav;
              
              Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj){
                  $blackRows = jQuery(".blackrow");
                  $nav = jQuery(".navbar");
                  $nav.removeClass("white");
                  $sitetitle = jQuery(".sitetitle span");
              });
              
              jQuery(document).on("scroll", function(){
          
                  $blackRows.each(function(){
                      var rect = this.getBoundingClientRect();
                      if(rect.top - offset < 0 && rect.bottom - offset > 0){
                          $nav.addClass("white");
                          $sitetitle.text( "NEW TITLE" );
                          return false;
                      }else{
                          $nav.removeClass("white");
                          $sitetitle.text( "OLD TITLE" );
                      }
                  });
              });
          </script>
          
          .blackrow {
              background: black;
          }
          
          .white {
              background: red;
          }
          

          Hope you get it to work!

          Best!

          Marius

          www.mariusjopen.world

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maarschalk
            wrote on Oct 12, 2018, 9:26 AM last edited by
            #10

            @mariusjopen said in Change color of fixed sitetitel/menu when scrolling down page (according to changing row-background):

            .blackrow {
            background: black;
            }

            .white {
            background: red;
            }

            Yes, thanks a lot for the effort Marius!!

            Best,
            Bart

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mariusjopen
              Global Moderator
              wrote on Oct 14, 2018, 8:47 PM last edited by
              #11

              Dear @maarschalk

              great! A pleasure!

              Marius

              www.mariusjopen.world

              1 Reply Last reply
              0
              • D Offline
                D Offline
                domphilcox
                wrote on Apr 3, 2024, 10:05 AM last edited by
                #12

                Hey Marius / Armin, I've been trying to apply the most recent code shared but with no joy. I have no experience in writing JQuery or JS from scratch but have managed to use many of the snippets you have kindly shared in the past. Given that this thread is six years old, I wonder if you could let me know if it should still work as described or if it's no out of date. Any help would be greatly appreciated. Thanks v much.

                1 Reply Last reply
                0
                • arminunruhA Offline
                  arminunruhA Offline
                  arminunruh
                  Global Moderator
                  wrote on Apr 4, 2024, 7:23 PM last edited by
                  #13

                  can you send your website address, /wp-admin/ username and password and a link to this topic to info@laytheme.com?

                  1 Reply Last reply
                  0
                  • arminunruhA Offline
                    arminunruhA Offline
                    arminunruh
                    Global Moderator
                    wrote on Apr 8, 2024, 2:12 PM last edited by arminunruh Apr 8, 2024, 10:14 AM
                    #14

                    put this js into lay options -> custom css & html -> custom html at bottom

                    <script>
                        var offset = 50;
                        var $blackRows;
                        
                        var $nav = jQuery(".laynav");
                        var $sitetitle = jQuery(".sitetitle");
                        
                        var checkIfOnABlackRow = function(){
                            $blackRows.each(function(){
                                var rect = this.getBoundingClientRect();
                                if(rect.top - offset < 0 && rect.bottom - offset > 0){
                                    $nav.addClass("white");
                                    $sitetitle.addClass("white");
                                    return false;
                                }else{
                                    $nav.removeClass("white");
                                    $sitetitle.removeClass("white");
                                }
                            });        
                        }
                        
                        window.laytheme.on('newpageshown', function(){
                            $blackRows = jQuery(".blackrow");
                            checkIfOnABlackRow();
                        })
                        
                        jQuery(document).on("scroll", function(){
                            checkIfOnABlackRow();
                        });
                    </script>
                    

                    by putting this into html at bottom we make sure the site title dom element and nav dom element can be selected cause they were loaded previously.

                    if we'd put this code into <head then we'd need to wait for jquery document ready or use newpageshown event to select these elements, it doesn't make a huge difference

                    and put this css into "custom css":

                    .white {
                        color: white !important;
                    }
                    
                    .white svg path{
                         fill: white;
                    }
                    

                    so your code almost worked.

                    the thing is your site title is a svg, so we need to target the paths of the css to get a fill of white. your css to do that didn't work.

                    also i improved the js a little so it also checks if we are on a black row when we land on a page, instead of just on scroll.

                    and you gave the rows a class of "blackrow" which u did correctly, by right clicking an empty spot in the row, choosing "set html class & id" and entering: blackrow for the class

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      domphilcox
                      wrote on Apr 8, 2024, 2:23 PM last edited by
                      #15

                      Yes, Armin! You're a legend. To not only look into this, but the tidy up the code AND explain where I went wrong and why it wasn't work, that's incredibly generous of you. I have a feeling your code will be used on plenty of sites in the future. Thanks again.

                      1 Reply Last reply
                      0
                      • arminunruhA Offline
                        arminunruhA Offline
                        arminunruh
                        Global Moderator
                        wrote on Apr 8, 2024, 2:27 PM last edited by
                        #16

                        oh thanks a lot!! :) <3

                        1 Reply Last reply
                        0
                        • arminunruhA arminunruh referenced this topic on Apr 8, 2024, 2:29 PM
                        • D domphilcox referenced this topic on Apr 9, 2024, 6:55 AM
                        • arminunruhA arminunruh referenced this topic on May 1, 2024, 9:31 PM
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        I also code custom websites or custom Lay features.
                        💿 Email me here: 💿
                        info@laytheme.com

                        Before you post:
                        1. When using a WordPress Cache plugin, disable it or clear your cache.
                        2. Update Lay Theme and all Lay Theme Addons
                        3. Disable all Plugins
                        4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

                        This often solves issues you might run into

                        When you post:
                        1. Post a link to where the problem is
                        2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
                        3. If the problem is difficult to explain, post screenshots / link to a video to explain it
                        Online Users
                        Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
                        laytheme.com
                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Search