The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Ignore function if..?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #36130

    So I have this top div (#topDiv) that appears when you scroll to almost the bottom of the page, and disappears when you scroll a bit up. There is also a “X” button on it that makes it slide up, but If you scroll it will just slide down again.

    This function get’s triggered when you scroll almost at the bottom:

    $(window).scroll(function() {
    if($(window).scrollTop() + $(window).height() > $(document).height() - 500) {
    $("#pagePush").slideDown(); // Ignore this

    This function get’s triggered when you scroll a bit up:

    if($(window).scrollTop() + $(window).height() < $(document).height() - 800) {

    And this function get’s triggered when you click the “X” button:

    return false;

    I want the “closeTop” to ignore the slideDown function, so that it won’t slide down again after you click that button.

    Thanks :)

    >>DEMO PAGE<<


    Is there no kind of “don’t call this function” or “don’t run” in jQuery?


    Hi schart!

    You could just use a flag to signal that the user had clicked the close button. I modified your code a bit to cache the functions that are called repeatedly (demo):

    // cache variables
    var win = $(window),
    wHeight = win.height(),
    dHeight = $(document).height(),
    divs = $('#topDiv, #pagePush'),
    flag = true; // flag is false when user has manually closed the divs

    .scroll(function() {
    if (flag) {
    if ( win.scrollTop() + wHeight > dHeight - 500) {
    if ( win.scrollTop() + wHeight < dHeight - 800) {
    // update variables when browser is resized
    wHeight = win.height();
    dHeight = $(document).height();

    $("#closeTop").click(function() {
    flag = false;
    return false;
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.