簡體   English   中英

盡管設置了垂直溢出,為什么垂直滾動條沒有出現?

[英]Why vertical scrollbar doesn't appear although vertical overflow is set?

我的邊欄有時大於主頁,我嘗試設置垂直溢出,但垂直滾動條仍然沒有出現。

/**
 * Created by eduard on 07.01.2016.
 */
console.log("Height 1 ", sidebar_height);

if ($(window).height() < sidebar_height + 35) {
    $('body').css('overflowY', 'auto');
    //$("#sidebar").css('overflowY', 'auto');
    console.log("Scrollbar should appear", $(window).height() - sidebar_height);
}
else {
    console.log("Scrollbar should not appear", $(window).height() - sidebar_height);
}

盡管設置了垂直溢出,為什么垂直滾動條沒有出現?

設置要scroll的值應該可以解決問題:

$('body').css('overflowY', 'scroll');

實質上,無論內容是否溢出,都會強制顯示滾動條。

編輯-或者,嘗試在窗口高度低於以下時添加一個類:

https://jsfiddle.net/0Lhwfjk6/

在這種情況下,我已經稍微簡化了樣例。 您需要調整實際瀏覽器窗口的大小。

jQuery的:

/**
 * Created by eduard on 07.01.2016.
 */
console.log("Height 1 ", sidebar_height);

if ($(window).height() < 300) {
    $('.content').addClass('scrollbar');
    //$("#sidebar").css('overflowY', 'auto');
    console.log("Scrollbar should appear", $(window).height() - sidebar_height);
}
else {
    console.log("Scrollbar should not appear", $(window).height() - sidebar_height);
}

CSS:

.scrollbar {
  overflow-y: scroll;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM