2013-08-05 126 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