0

I have this piece of code

$(function(){
var padding1 = [1,15];
var fontSize = [18,23];


  var changeNavState = function(newStateIndex) {
    $("nav ul li a").data('state', newStateIndex).stop().animate({
        padding : padding1 [newStateIndex] + 'px'
    }, 300); 
    $("nav ul li a").data('state', newStateIndex).stop().animate({
        fontSize : fontSize [newStateIndex] + 'px'
    }, 300); 

  };

  var boolToStateIndex = function(bool) {
    return bool * 1;    
  };

  var maybeChangeNavState = function(condState) {
    var navState = $("nav ul li a").data('state');
    if (navState === condState) {
      changeNavState(boolToStateIndex(!navState));
    }

  };

  $('nav ul li a').data('state', 1);

  $(window).scroll(
      function(){
        if ($(document).scrollTop() > $('#home').offset().top - $('nav').height()) {
          maybeChangeNavState(1);
        } else {
          maybeChangeNavState(0); 
        }
     }
  );
}

);

So when the user scrolls greater than hight of 'home' then the navbar padding should be 1 and font size 18 and when its minor padding should be 15 and fontSize 23. The problem is that it works only for fontSize BUT if i erase fontSize code the padding works.. Does anyone knows what is going on ? Thanks!

1 Answer 1

1

Not sure if this is the reason or not... but I would change your animation code to:

$("nav ul li a").data('state', newStateIndex).stop().animate({
    padding : padding1 [newStateIndex] + 'px',
    fontSize : fontSize [newStateIndex] + 'px'
}, 300); 

Combining the two together. Perhaps the two are conflicting?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bro! That was the problem.. Silly me for not seing that. Cheers. I will tick when i can ;d
Also, if this was me, I would opt for a css solution: nav ul li a { transition: all 0.3s; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.