If scrollpast? More jquery problems

Hi,

I have two functions for an <a>, that I want to add some conditionals to.

The two are:

$("#tofilter").click(function(e) {
  e.preventDefault();
  $('html, body').animate({
    scrollTop: $("#filter").offset().top - 80
  }, 1000);
});

AND

$("#tofilter").click(function(e) {
    e.preventDefault();
    $('.stick-filter').toggleClass('filter-state');
});

What I want to do is something like this:

IF SCROLLPAST #DIV + 300PX {
     $("#tofilter").click(function(e) {
        e.preventDefault();
        $('.stick-filter').toggleClass('filter-state');
    });
} ELSE {
   $("#tofilter").click(function(e) {
      e.preventDefault();
      $('html, body').animate({
        scrollTop: $("#filter").offset().top - 80
      }, 1000);
    });
}

But i don’t know how the if statement would look?

EDIT: tried this but doesnt seem to be working:

$(document).ready(function(){
    var window_top = $(window).scrollTop();
    var div_top = $('.filter-anchor').offset().top + 300;
    if (window_top > div_top) {
        $("#tofilter").click(function(e) {
            e.preventDefault();
            $('.stick-filter').toggleClass('filter-state');
        });
    } else {
         $("#tofilter").click(function(e) {
          e.preventDefault();
          $('html, body').animate({
            scrollTop: $("#filter").offset().top - 80
          }, 1000);
        });     
    }
});

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.