2011-11-21 117 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); 
    }); 
    });