Forums

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

Home Forums JavaScript Problem for clever person to solve

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32172
    msevrens
    Member

    Can’t figure out what’s wrong with this code:

    $(document).ready(function(){

    var wheight = $(window).height(),
    dheight = $(document).height(),
    push = 0;

    if (wheight > dheight){
    push = wheight - dheight;
    $('#pushdiv').height(push);
    }

    $(window).resize(function() {
    wheight = $(window).height();
    dheight = $(document).height();
    changepush();
    });

    function changepush() {
    if (wheight > dheight) {
    push += 1
    $('#pushdiv').height(push);
    }

    else if ((wheight < dheight) && (push>0)){
    push -= 1
    $('#pushdiv').height(push);
    }

    else {
    }
    }
    });

    My problem is that when you zoom out from the page, or if theres not enough content, then the page extends beyond the footer.

    So, I essentially want a sticky footer, but theres a variety of other things I want to do besides just have a sticky footer when the page resizes. So I want to do this with javascript, and be able to store the difference between the height of the window and the height of the document, and have this automatically update as the window resizes in a variable, so I can use that to resize other elements on the page.

    So what I did, was first, set the height of the window and the document to the variables wheight and dheight and set a variable (push) to 0 which would represent the difference in height between the two.

    If, when the page loads, the height of the window is greater than the height of the document, I want to set the height of my variable push to wheight – dheight, then set a div in the html to that value.

    Then every time the window resizes, first i want to update the variables wheight and dheight, then run a function called changepush.

    In changepush, if the height of the window is greater than the height of the document, i want to add 1 to push, then set the height of the div in the html to that value. If instead the height of the window is less than the height of the document and push hasn’t gone below 0 yet (meaning that the window hasn’t descended below the height of the document) then I want to decrease the variable push by one and then set the height of the push div to that value. Finally, if the window height = the document height and my variable push = 0 then I don’t want to do anything.

    Ok… so I wrote all that, and to me it looks like it’s right, but… nothing happens. I feel like I’m fundamentally misunderstanding something. Can you see an error? Absolutely nothing happens. I feel like at LEAST if the window height is greater than the document height when the page loads, then the div should be set to the difference between the two, but nothing happens.

    Please help me obi-wan kenobi, you’re my only hope. (Seriously, I don’t know anyone who knows javascript).

    #51464
    angus
    Participant

    Try adding parameters to changePush(), and pass in wheight and dheight. Those two variables might not be accesible inside the function.

    Also, you forgot a semicolon after “push += 1”. And I’m not really sure what that’s supposed to do…

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.