I was planning to post this at learningjquery.com eventually, but since you asked...

Here is what I do to apply the ScrollTo() feature of Interface to only same-page links. Note that I have it look only inside #main- content, but you can remove or replace that. By the way, I had to start with [EMAIL PROTECTED]"#"], using the asterisk, because IE always uses the fully-qualified URL (so we can't just find "#" at the beginning).


// smooth scrolling for all same-page links *wrap this in a $ (document).ready(function{});

  var docHashIndex = location.href.indexOf("#");
  if (docHashIndex != -1) {
    var docURL = location.href.slice(0,docHashIndex);
  }
  else {
    var docURL = location.href;
  }

  $('#main-content [EMAIL PROTECTED]"#"]').click(function() {
    var $linkHref = $(this).href();
    var linkHashIndex = $linkHref.indexOf('#');
    var linkURL = $linkHref.slice(0,linkHashIndex);
    var linkHash = $linkHref.slice(linkHashIndex);

    if (docURL == linkURL) {
      if ($(linkHash).length > 0 ) {
        $(linkHash).ScrollTo(400);
        return false;
      } else {
        $linkDest = $("[EMAIL PROTECTED]" + linkHash.slice(1) +']');
        if ($linkDest.length > 0) {
          $linkDest.ScrollTo(400);
          return false;
        }
      }
    }
  });



--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 18, 2007, at 6:59 AM, [-Stash-] wrote:


Many thanks to Stefan for helping me with this off list.


If anyone else wants to get this working with a single external file, so
your header has something like this in it:


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="interface.js"></script>
<script type="text/javascript" src="ScrollToAnchors.js"></ script>


ScrollToAnchors.js should contain the following:


$(document).ready(
   function()
   {
      $(document).ScrollToAnchors(630);
   }
);

Change the ScrollToAnchors() value to whatever you like. Higher number ->
slower scrolling.


I have a problem with it though. Scrolling between anchors on the same page works perfectly, but when trying to go to another page, the links don't work
at all!  The Top of Page and Bottom of Page links on
http://exhibitq.com/talk/comments.php?DiscussionID=3&page=1 this page work as expected, but if I try clicking on any of http://exhibitq.com/ talk/ the
discussion links on the main discussions page  nothing happens!


I realise that I could specify exactly which anchors I would like the plugin to work for, but I would rather it would just work as expected by default.
What would I need to change to get these links to other pages to work
properly?


P.S. please feel free to sign up to the forums if you want to test things
out, it's just a general testing zone for me.

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to