Make scrollbars only visible when a Div is hovered over?

后端 未结 10 2028
庸人自扰
庸人自扰 2020-12-02 15:04

I am trying to figure out how to have a scrollable div that only shows its scrollbars when Hovered.

Example is Google Image search, in the image below you can see

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 15:58

    If you are only concern about showing/hiding, this code would work just fine:

    $("#leftDiv").hover(function(){$(this).css("overflow","scroll");},function(){$(this).css("overflow","hidden");});
    

    However, it might modify some elements in your design, in case you are using width=100%, considering that when you hide the scrollbar, it creates a little bit of more room for your width.

提交回复
热议问题