skaterdav85 Posted March 3, 2011 Share Posted March 3, 2011 You know how you can jump down/up to a particular part of the page if you put the element's id in the url? So by putting the id in the href attribute of an anchor, you can cause the page to jump to that id. <div id="div1">this is my div</div><a href="#div1">somewhere on the page</a> Is there a way to control this behavior in JavaScript? I have points on a map and each point knows which ID to jump to, but I don't know how to tell it to jump to a particular ID on the page when clicked. I have already added a click event listener to each point. I just need to make it do the jumping part. Link to comment Share on other sites More sharing options...
Ingolme Posted March 3, 2011 Share Posted March 3, 2011 Make each point an <a> element with the href attribute. Or use can use image maps to make a specific part of an image behave like a link. Link to comment Share on other sites More sharing options...
boen_robot Posted March 3, 2011 Share Posted March 3, 2011 There's the scrollTo() and scrollBy() methods, but they scroll to coordinates, not to elements. If you want to get a "scroll compatible" position of an element, you'll probably have to look at the scroll* properties of the element. Link to comment Share on other sites More sharing options...
Ingolme Posted March 3, 2011 Share Posted March 3, 2011 The scrollIntoView() method will scroll to any element. It works with all browsers: http://www.quirksmode.org/dom/w3c_cssom.html#t23 Link to comment Share on other sites More sharing options...
skaterdav85 Posted March 4, 2011 Author Share Posted March 4, 2011 thanks guys. scrollIntoView() is exactly what I am looking for. I didn't even know about this method. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.