简体   繁体   English

使用jQuery(或JavaScript)在div内滚动并溢出

[英]Scroll inside a div with overflow using jquery (or javascript)

I have a div with a fixed height and overflow-y : scroll which I am loading via ajax. 我有一个固定高度和div -y的div:我通过ajax加载的滚动。 I'm currently looking for a possibility to scroll the content inside the div (using the mouse wheel) but without displaying the scroll bar. 我目前正在寻找一种在div内滚动内容(使用鼠标滚轮)但不显示滚动条的可能性。 Can anyone help? 有人可以帮忙吗?

Another way is to use jquery.mousewheel : https://github.com/brandonaaron/jquery-mousewheel 另一种方法是使用jquery.mousewheel: https : //github.com/brandonaaron/jquery-mousewheel

On mouse wheel, compute scroll urself : 在鼠标滚轮上,计算urself滚动:

$('.toScroll').on('mousewheel',function(event, delta, deltaX, deltaY){
    if(!$(this).attr('data-scrolltop')){
        $(this).attr('data-scrolltop',0);
    }
    var scrollTop = parseInt($(this).attr('data-scrolltop'));
    scrollTop += (-deltaY * lineHeight);
    $(this).attr('data-scrolltop',scrollTop);
    $(this).scrollTop(scrollTop);
});

I made a Fiddle as a demonstration : http://jsfiddle.net/W2pZB/ 我做了一个小提琴作为演示: http : //jsfiddle.net/W2pZB/

The only problem is about the var-fixed line height. 唯一的问题是关于var-fixed线的高度。

You can do it by applying overflow:hidden and after display-none on the scroll-bar using css 您可以通过使用cssoverflow:hiddenoverflow:hidden display-nonescroll-bar上应用后执行此操作

And here you can find a same thing in below question . 在下面的问题中,您可以找到相同的内容。

jQuery: How do I scroll the body without showing the scroll bar? jQuery:如何在不显示滚动条的情况下滚动正文?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM