View Full Version : Problem with content sliding

02-19-2011, 12:30 AM

So i am using this page scrolling script, which yes, is written specifically for the whole page to scroll, i am trying to make a div scroll. Which is working for me, but sliding in a very weird way, it kind of jumps. Anyone know why??

Thanks in advance!! Code and link below!

http://experiencemediaonline.gorillaonemedia.com/services/ <-- click on the side menu links, see how it slides then jumps??

$(function() {

function filterPath(string) {
return string

var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('div#services');

// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
$('a[href*=#]').each(function() {

// Ensure it's a same-page link
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {

// Ensure target exists
var $target = $(this.hash), target = this.hash;
if (target) {

// Find location of target
var targetOffset = $target.offset().top;
$(this).click(function(event) {

// Prevent jump-down

// Animate to target
$(scrollElem).animate({scrollTop: targetOffset}, 700, function() {

// Set hash in URL after animation successful
location.hash = target;



// Use the first element that is "scrollable" (cross-browser fix?)
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
var isScrollable = $scrollElement.scrollTop()> 0;
if (isScrollable) {
return el;
return [];


02-20-2011, 06:58 AM
It works smoothly on a Macbook. This is what I use for scrolling(a lot simpler if you manage to make it work for your purpose):

$('a[href=#top]').click(function(){//when this is clicked: <a href="#top">Back to top</a>
$('html, body').animate({scrollTop:0}, 'slow');
return false;

//and then add a link to where you want to scroll: <a name="top"></a>

02-20-2011, 08:38 PM
Thanks!! I ended up going a different route, but I could use this if i change my mind! Thanks again!