Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble assigning background color on scroll

I'm trying to change the design of my hamburger navigation as the user scrolls. I feel I have come semi close https://jsfiddle.net/g95kk7yh/6/

$(document).ready(function(){       
        var scroll_pos = 0;
        $(document).scroll(function() { 
            scroll_pos = $(this).scrollTop();
            if(scroll_pos > 10) {
                $(".navigation").css('background', 'rgba(255, 0, 0, 0.5)');
                $(".navigation span").css('background', '#bdccd4');
            } else {
                $(".navigation").css('background', 'transparent');
                $(".navigation span").css('background', '#fff');
            }
        });
    });

Here is what I'm trying to achieve

enter image description here

The main problem I'm having is assigning the correct width and height of the red box without repositioning the navigation menu as a whole.

Also is it possible to only have these changes at 600px and under (as you can see this is when the hamburger menu shows).

like image 789
ccc Avatar asked Apr 03 '16 08:04

ccc


People also ask

Which Property is responsible for setting the background color?

The background-color CSS property sets the background color of an element.


1 Answers

I have used @potatopeelings post and have changed few lines and added.

.myClass {
  margin-right: -25px;
  width: 85px;
  height: 85px;
  background-color: rgba(255, 0, 0, 0.5);
}

Fiddle: https://jsfiddle.net/moj7z2b4/2/

like image 128
7urkm3n Avatar answered Sep 28 '22 02:09

7urkm3n