jQuery(function($) {
function fixDiv() {
var $cache = $('header');
if ($(window).scrollTop() > 10)
$cache.css({'position': 'fixed', 'top': '0', 'background': 'rgba(0,0,0,0.8)', 'padding': '0'});
//$('#top-menu a').css({'padding': '17px 20px'});
else
$cache.css({'position': 'absolute', 'top': '0', 'background': 'rgba(0,0,0,0)', 'padding': '20px 0'});
//$('#top-menu a').css({'padding': '30px 20px'});
}
$(window).scroll(fixDiv);
fixDiv();
});
This is currently what I have, and i see var $cache = header so I wanted to add another line so when it changes the background it also changes the font size of the header.. so I now have
jQuery(function($) {
function fixDiv() {
var $cache = $('header');
if ($(window).scrollTop() > 10)
$cache.css({'position': 'fixed', 'top': '0', 'background': 'rgba(0,0,0,0.8)', 'padding': '0'});
$('h1').css({'font-size': '26px'});
else
$cache.css({'position': 'absolute', 'top': '0', 'background': 'rgba(0,0,0,0)', 'padding': '20px 0'});
$('h1').css({'font-size': '36px'});
}
$(window).scroll(fixDiv);
fixDiv();
});
What did I do wrong?
Multiple statements require braces:
Indenting your code properly makes it more obvious why it wasn’t working:
(not only wrong but invalid – the
elseis orphaned).