Reputation: 11
I'm trying to start an auto scroll on-page load for a jscrollpane implementation. The reason being is using the anchor links to scroll to elements in the pane area when there is a lot of content seems to mess up the calculation of scroll height.
Example here: http://sunlight.pixelalchemy.com.au/tiltrak
(after page loads click on the lowest link "Bottom weights" and you'll see the problem)
If you use the manual scroll (drag the blue bar) first. Then use the links it works OK. So I'm trying to make it autoscroll on page load to an element at the top to mimic what appears to work as a solution. (using autoReinitialise didn't seem to work for me)
This site seems to do an autoscroll to a class element which I've tried to reproduce on the site I'm working on: http://onomadesign.com/wordpress/identity-design/china-packaging-corporation/
My on page code to do this is:
$(function()
{
// Set up #pane4 and the links which scrollTo elements within it
var $pane4 = $('#contentPanel');
$pane4.jScrollPane({animateTo:true});
$pane4.scrollTo('.productInfo');
$('a.scroll-to-element-demo').bind(
'click',
function()
{
var targetElementSelectorString = $(this).attr('rel');
$pane4[0].scrollTo(targetElementSelectorString);
return false;
}
);
});
//left content panel slide in to appear on document ready
$(document).ready(function () {
$("#mainContent").animate({"right": "+=673px"}, "3000");
});
I also tried to add this to the on document ready part (at the bottom of the page js):
$("#mainContent").scrollTo('.productInfo');
Both don't seem to work.
Please help, I'm a newbie to jQuery who has really tried to sort this one and spent sooo much time on it, so any assistance on this I'd be really happy to receive.
Upvotes: 1
Views: 3408
Reputation: 3214
It looks like you are using a very old version of jScrollPane (v1) rather than the current (v2). You can find the current version here and may find it easier to work with:
http://jscrollpane.kelvinluck.com/
There is an example of using the scrollToY method of the API here:
http://jscrollpane.kelvinluck.com/scroll_to.html
Basically you need a reference to the API and then you simply call scrollToY (or scrollToElement)...
Upvotes: 1