I ran into this problem exactly when I created a โpreloaderโ for my site. Anyway, the way I solved my problem was to change the background-color to backgroundColor . Make sure backgroundColor not in quotation marks, just enter it the way you would do with a variable or function, etc.
From jQuery API Docs :
In addition, jQuery can interpret CSS and DOM formatting the properties of multiple words in the same way. For example, jQuery understands and returns the correct value for .css({ "background-color": "#ffe", "border-left": "5px solid #ccc" }) and .css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" }) . Note that in DOM notation, quotation marks around property names are optional, but with a CSS notation, they are required due to a hyphen in the name.
This code should work, but I have not tested it. I changed your .css('property', 'value') to .css({'property': 'value' });
$(document).ready(function() { var scroll_pos = 0; $(document).scroll(function() { scroll_pos = $(this).scrollTop(); if (scroll_pos > 10) { $(".navigation").css({ backgroundColor: 'rgba(255, 0, 0, 0.5)' }); $(".navigation span").css({ 'background': '#bdccd4' }); } else { $(".navigation").css({ backgroundColor: 'transparent' }); $(".navigation span").css({ 'background': '#fff' }); } }); });
source share