admin管理员组

文章数量:1303536

I'm using the following jQuery function to smoothly scroll to page sections:

function scrollTo(element) {    
    //$('html, body').animate({           // before the addition of jscrollpane
    $('#full-page-container').animate({   // after addition of jscrollpane
        scrollTop: $(element).offset().top
    }, 1500);
}

I've added jscrollpane to replace the default page scrollbar, and it seems that the animate function with scrollTop above won't work with jscrollpane, but works flawlessly without it.

Is it possible to use both jscrollpane and animate with scrollTop ?

I'm using the following jQuery function to smoothly scroll to page sections:

function scrollTo(element) {    
    //$('html, body').animate({           // before the addition of jscrollpane
    $('#full-page-container').animate({   // after addition of jscrollpane
        scrollTop: $(element).offset().top
    }, 1500);
}

I've added jscrollpane to replace the default page scrollbar, and it seems that the animate function with scrollTop above won't work with jscrollpane, but works flawlessly without it.

Is it possible to use both jscrollpane and animate with scrollTop ?

Share Improve this question edited Sep 26, 2012 at 2:12 Eli 14.8k5 gold badges61 silver badges77 bronze badges asked Apr 21, 2011 at 2:20 JeffJeff 2,8628 gold badges32 silver badges35 bronze badges 1
  • 1 Did you not get a good enough answer, Deca? – Levi Morrison Commented May 24, 2011 at 19:41
Add a ment  | 

2 Answers 2

Reset to default 6

No, you can't use scrollTop.

However, scrollpane has their own built in scrolling, which you can see examples of here.

Scroll To - JScrollPane

Example, taken from the jScrollPane site:

var api = pane.data('jsp');

    $('#but-scroll-to').bind(
        'click',
        function()
        {
            // Note, there is also scrollToX and scrollToY methods if you only
            // want to scroll in one dimension
            api.scrollTo(parseInt($('#toX').val()), parseInt($('#toY').val()));
            return false;
        }
    );

Notes: You can't animate() and jScrollPane together. However, jScrollPane is nice enough to include this feature. It isn't very intuitive, but I made a some examples for you. Cheerio!

See the jScrollPane API for more useful information.


I had some examples, but jsfiddle is hanging on them (I can't even see the source code), so I have removed them.

本文标签: javascriptcan39t use animate scrollTop with jscrollpaneStack Overflow