2011-11-21 118 views
3

我正在为我的网站使用SlimScroll插件。重置窗口大小调整功能

我想重置/重新启动窗口大小的slimscroll函数,因为高度和宽度应根据#content_wrapper div的高度和宽度进行更改。

我试过了几种方法,但似乎没有什么关系。在我目前的代码下面。有谁知道我能做到这一点?

$('#content_wrapper').slimScroll({ 
    width: $('#content_wrapper').css({'width':(($(window).width())-240)+'px'}), 
    height: $('#content_wrapper').css({'height':(($(window).height())-65)+'px'}) 
}); 

// scrollbar onresize resetten 
$(window).resize(function(){  
    $('#content_wrapper').slimScroll({ 
     width: $('#content_wrapper').css({'width':(($(window).width())-240)+'px'}), 
     height: $('#content_wrapper').css({'height':(($(window).height())-65)+'px'}) 
    }); 
}); 
+0

你为什么要从window.width减去240和65? – Purag

+0

因为65px是页脚的高度,而240px是菜单的宽度。 –

+0

我明白了。为了让它看起来更好,可以尝试在变量中添加新的宽度/高度,并在slimScroll函数中设置变量。 (我也注意到你有$(window)> height()' - 你不需要)括号。 – Purag

回答

0

可能:

$('#content_wrapper').slimScroll({ 
    width: (($(window).width())-240)+'px', 
    height: (($(window).height())-65)+'px' 
}); 

// scrollbar onresize resetten 
$(window).resize(function(){  
    $('#content_wrapper').slimScroll({ 
     width: (($(window).width())-240)+'px', 
     height: (($(window).height())-65)+'px' 
    }); 
}); 
+0

感谢您的回答。试过了,但没有奏效。 –

1

我明白这个问题被问了很久,但我面临同样的问题,并找到了一些解决办法,这里是我面对的问题的解决方案。

// Resetting slim scroll 
function applySlimScroll(){ 
    $('#content_wrapper').slimScroll({ 
     width: $('#content_wrapper').css({'width':(($(window).width())-240)+'px'}), 
     height: $('#content_wrapper').css({'height':(($(window).height())-65)+'px'}) 
    }); 
} 

// Resetting slim scroll 
function resetSlimScrollLessonSlide(){ 
    $('.slimScrollDiv #content_wrapper').unwrap(); 
    $('.slimScrollBar, .slimScrollRail').remove(); 
} 

// Let the resize event interval be larger, so resized in 500ms! 
function resizedw(){ 
    resetSlimScrollLessonSlide(); 
    applySlimScroll() 
} 

var doit; 
$(window).resize(function() { 
    clearTimeout(doit); 
    doit = setTimeout(resizedw, 500); 
}); 
7

恰好碰到了这个问题,今天,这对我的作品: 初始化slimScroll时,它增加了一个div类“slimScrollDiv”。你可以改变这个div的高度,并将其设置为与你的包装div相同...

$(document).ready(function(){ 
    $('#scrollDiv').slimScroll({ 
     height: 'auto' 
    }); 

    $(window).resize(function(){ 
     var h=$(window).height()-250; 
     $('#scrollDiv').height(h); 
     $('.slimScrollDiv').height(h); 
    }); 
    });