Jack Johnson
Jack Johnson

Reputation: 611

jQuery increasing and decreasing div height based on scroll positioning

jQuery increasing and decreasing div height based on scroll positioning.

Was wondering if any of you know of any way to do this in a good way. Let's say i have a div with and id of "scroll-element" And when i scroll down the page, let's say down like 500px it starts to increase to about 200px when scrolling down and decreasing to 0px when i scroll back up. I tried a few methods but none have worked so far.

Upvotes: 1

Views: 4743

Answers (1)

DevlshOne
DevlshOne

Reputation: 8457

Something like this?

jsFiddle

$(function () {
    $(window).scroll(function () {
        var $myDiv = $('#scroll-element');
        var y = $(this).scrollTop();
        $('#results').text(y);
        x = y - 300;
        $myDiv.animate({height:x},2500);
    }).scroll();
});

Upvotes: 1

Related Questions