tags:

views:

21

answers:

1

I'm trying to use 2 pieces of jquery together – they work individually but not together.

checkShow();
        function checkShow() {
            var top = 0;
            top = $(window).scrollTop();

            if(top >= 600 && top < 1800) {
             $('#lift:hidden').fadeIn({duration:500});
            } else {
               $('#lift').fadeOut({duration:1000});
            }
            if(top < 1800){
                $("a[href='#uk']").parent().addClass("current");
                $("a[href='#uk']").parent().siblings().removeClass("current");
            }
            if((top >= 1800) && (top < 3000)){
                $("a[href='#mcr']").parent().addClass("current");
                $("a[href='#mcr']").parent().siblings().removeClass("current");
            }    
            if((top >= 3000) && (top < 4000)){      
                $("a[href='#lpool']").parent().addClass("current");
                $("a[href='#lpool']").parent().siblings().removeClass("current");
            }
            if((top >= 4000) && (top < 5000)){      
                $("a[href='#bham']").parent().addClass("current");
                $("a[href='#bham']").parent().siblings().removeClass("current");
            }
            if((top >= 5000) && (top < 6000)){      
                $("a[href='#offers']").parent().addClass("current");
                $("a[href='#offers']").parent().siblings().removeClass("current");
            }
            if((top >= 6000) && (top < 7000)){      
                $("a[href='#groups']").parent().addClass("current");
                $("a[href='#groups']").parent().siblings().removeClass("current");
            }
            if((top >= 7000)){     
                $("a[href='#groups']").parent().addClass("current");
                $("a[href='#groups']").parent().siblings().removeClass("current");
            }

        }
        $(window).scroll(checkShow);

and

var sbtop = $('#sidebar').offset().sbtop - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
        $(window).scroll(function (event) {
            // what the y position of the scroll is
            var y = $(this).scrollTop();

            // whether that's below the form
            if (y >= sbtop) {
              // if so, ad the fixed class
              $('#sidebar').addClass('fixed');
            } else {
              // otherwise remove it
              $('#sidebar').removeClass('fixed');
            }
          });

I can only assume it's something to do with $(window).scroll ...?

+1  A: 

Not really answering your question, but:

function checkShow() {
  var top = $(window).scrollTop();

  if(top >= 600 && top < 1800) {
    $('#lift:hidden').fadeIn({duration:500});
  } else {
    $('#lift').fadeOut({duration:1000});
  }

  var map = {'1800':'uk','3000':'mcr','4000':'lpool','5000':'bham','6000':'offers','7000':'groups'};
  var done = false;

  $.each(map, function(px,id) {
    if (top < parseInt(px)) {
      setCurrent(id); 
      done = true;
    }
  });
  if (!done) setCurrent('groups');

  function setCurrent(id) {
    $("a[href='#"+id+"']").parent().addClass("current").siblings().removeClass("current");
  }
}
Tomalak