2013-08-05 132 views
0

我想實現tyniscrollbar我的div元素的形式。 我想使它與窗口滾動條同步,以便當它到達頁面窗口的底部時,滾動條應該會自動向下滾動並使用div滾動條,以便我可以看到我的div的所有內容,請幫助我。我想實現div滾動條相對於窗口滾動條

回答

0

我沒有測試它,但這應該做的伎倆

var heightDiv = document.getElementById('#div1').clientHeight; 
var height = document.body.offsetHeight; 

jQuery(document).scroll(function(){ 

    var moved = jQuery(window).scrollTop(); 
    var ratio = moved*heightDiv/height; 
    jQuery('#div1').animate({scrollTop: ratio}); 
}) 
+0

thanx的解決方案,我申請,但其沒有工作..... – Zorba

+0

你可以寫在jsfiddle.net? – GwenM

+0

'/ *我已經implimented像這樣請幫助*/$(文件)。就緒(函數(){ \t \t \t \t \t \t $(」 scrollbar1' 。)tinyscrollbar(); \t \t \t 。 $(」。scrollbar1 ')滾動(函數(){ VAR heightDiv =的document.getElementById(' scrollbar1' 。)clientHeight; 警報(heightDiv); VAR高度= document.body.offsetHeight; jQuery的(document).scroll(function(){ var moved = jQu ERY(窗口).scrollTop(); var ratio =移動* heightDiv * 20/height; jQuery('。scrollbar1')。animate({scrollTop:ratio}); }) }); });' – Zorba