wieringen / tinyscrollbar

A lightweight cross browser javascript scrollbar.
http://baijs.com/tinyscrollbar
Other
398 stars 203 forks source link

support for on page navigation / scroll to / anchors #36

Open deanbot opened 9 years ago

deanbot commented 9 years ago

Noticing the following issues with named anchors (i.e. #terminology) within scrollbox content:

  1. navigating manually to a url that includes a location (i.e. mysite.com/my-page#myloc):
    • content is in the correct location
    • thumb is not in the correct location. it's set to 0
  2. clicking a link on a page which links to a location on the same page:
    • nothing happens other than the url updating
wieringen commented 9 years ago

I think this can be done by extending tinyscrollbar using the current methods. Not sure about how I feel about implementing this by default.

deanbot commented 9 years ago

Hmm. To implement I converted # signs to query strings - grabbing the value and navigating using the following method on page load. Linking to areas on the same page was accomplished by adding a special class to links and locations - navigating on click. I could not get # signs to work.

Linking to an area on the same page required using position() where handling the location on page load required offset.

navigateToScrollLocation = function(loc, usePosition) {
    if(!loc)
      return;

    // if clicking within the content use position instead of offset
    var l = $('.sloc-'+loc),
      lo = l ? (usePosition ? l.position() : l.offset() ) : false,
      lp = lo ? lo.top : false,
      lf = usePosition ? lp + 20 : lp - 150;

    if(lo)
      _this.scrollbarOptions.update(lf);
  };