最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - can't use animate scrollTop with jscrollpane? - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论