Results 1 to 2 of 2

Thread: need help dynamically calculating "bottom" relative to another div - using jquery?

  1. #1
    Join Date
    Feb 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help dynamically calculating "bottom" relative to another div - using jquery?

    hi all,

    i'm a novice at scripting etc, but have been tying the below code:

    Code:
    $(function() {
        $.fn.scrollBottom = function() {
            return $(document).height() - this.scrollTop() - this.height();
        };
    
        var $el = $('#wrap');
        var $window = $(window);
    
        $window.bind("scroll resize", function() {
            var gap = $window.height() - $el.height() - 10;
            var visibleFoot = 1233 - $window.scrollBottom();
            var scrollTop = $window.scrollTop()
    
            if(scrollTop < 100 + 10){
                $el.css({
                    top: (100 - scrollTop) + "px",
                    bottom: "auto"
                });
            }else if (visibleFoot > gap) {
                $el.css({
                    top: "auto",
                    bottom: visibleFoot + "px"
                });
            } else {
                $el.css({
                    top: 0,
                    bottom: "auto"
                });
            }
        });
    });
    which is basically making my #wrap div stay fixed in view as the customer scrolls down my page.

    It then stops scrolling at 1233 pixels from bottom as per the "var visibleFoot" in above code...

    This is working great for me, all but the 1233 pixels - it can vary per page, and ideally i'd like the script to dynamically stop 30 pixels above my #reviews div.

    So i guess what i would ideally need is above code to calculate how many pixels, the top of the #review div is, from the bottom of the page.

    If anyone can help with this, would be great.

    kind regards
    James
    Last edited by jscheuer1; 11-26-2013 at 03:07 AM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Replace 1233 with:

    Code:
    $(document).height() - $('#review').offset().top
    Last edited by jscheuer1; 11-26-2013 at 03:24 PM. Reason: add text
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Add "scroll to bottom" option to "jQuery Scroll to Top Control v1.1"
    By YesHoney in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-10-2010, 04:55 PM
  2. Replies: 0
    Last Post: 08-25-2009, 06:59 PM
  3. Replies: 0
    Last Post: 04-11-2009, 08:48 AM
  4. Replies: 1
    Last Post: 01-13-2009, 01:30 PM
  5. HTML code for "Bottom Frame Layout"
    By devajyoti in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 12-10-2008, 06:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •