Forums

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

Home Forums JavaScript jQuery custom scrolling math help

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #35168
    mikes02
    Participant

    I am using this custom scrollbar on a div http://manos.malihu.gr/jquery-custom-content-scroller and outside of the div is an anchor that when clicked is supposed to scroll down to a specified ID within the scrollable div, on that website someone posted this function:

    function scrollToItem(item)
    {
    var n = item.position().top;
    var c = $(".container");
    var c_h = c.height();
    var d = $(".dragger");
    var d_h = $(".dragger_container").height();
    var d_p = parseInt(n * (d_h / c_h));

    c.animate({top: -n},1000);
    d.animate({top : d_p},1000);
    }

    and it is called like this:

    	$('#leave-comment').click(function()
    {
    scrollToItem($("#comments"));
    });

    and this is the HTML that has to wrap the content:

                        




    This is a header


    Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus


    Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus













    However, I think the math may be off on this because I am not getting an accurate scrolling effect, when the anchor is clicked the scrolling effect takes place but it scrolls much further down than it is supposed to, in fact the dragger on the scrollbar goes beyond the dragger container and it creates a lot of empty space at the bottom of the scrollable div. Any ideas on how to get this functional or what might be causing the excess space?

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