Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 隐藏可滚动div的滚动条_Javascript_Jquery_Css_Html - Fatal编程技术网

Javascript 隐藏可滚动div的滚动条

Javascript 隐藏可滚动div的滚动条,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我正在开发HTML5应用程序,因此没有固定高度。我想使我的div可滚动,但滚动条不应可见。有没有办法做到这一点 HTML: <!DOCTYPE html> <html> <body> <div id="chatlist" class="mousescroll gridcontainer"> <ul> <li>Aug 19, 2011 - Here is an update to

我正在开发HTML5应用程序,因此没有固定高度。我想使我的
div
可滚动,但滚动条不应可见。有没有办法做到这一点

HTML:

<!DOCTYPE html>
<html>
<body>
    <div id="chatlist" class="mousescroll gridcontainer">
        <ul>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>

        </ul>
    </div>
</body>
</html>
<style>
    .gridcontainer {
      position: absolute;
      top: 0; bottom: 0; left: 0; right: 0;
      overflow: auto;
    }
        div#chatlist {
        /**width: 50px;
        height: 540px;**/
        border: 1px solid black;
    }
    div.mousescroll {
        overflow: hidden;
    }
    div.mousescroll:hover {
        overflow-y: scroll;
    }
    ul {
        list-style-type: none;
        padding-left: 10px;
        padding-right: 10px;
    }
    .slimScrollDiv { border: 1px solid #ccc; margin:10px; }
    li {
        margin-bottom:20px;
    }
</style>
<script>
(function($) {

    jQuery.fn.extend({
        slimScroll: function(o) {

            var ops = o;
            //do it for every element that matches selector
            this.each(function(){

            var isOverPanel, isOverBar, isDragg, queueHide, barHeight,
                divS = '<div></div>',
                minBarHeight = 30,
                wheelStep = 30,
                o = ops || {},
                cwidth = o.width || 'auto',
                cheight = o.height || '250px',
                size = o.size || '7px',
                color = o.color || '#000',
                position = o.position || 'right',
                opacity = o.opacity || .4,
                alwaysVisible = o.alwaysVisible === true;

                //used in event handlers and for better minification
                var me = $(this);

                //wrap content
                var wrapper = $(divS).css({
                    position: 'relative',
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                }).attr({ 'class': 'slimScrollDiv' });

                //update style for the div
                me.css({
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                });

                //create scrollbar rail
                var rail  = $(divS).css({
                    width: '15px',
                    height: '100%',
                    position: 'absolute',
                    top: 0
                });

                //create scrollbar
                var bar = $(divS).attr({ 
                    'class': 'slimScrollBar ', 
                    style: 'border-radius: ' + size 
                    }).css({
                        background: color,
                        width: size,
                        position: 'absolute',
                        top: 0,
                        opacity: opacity,
                        display: alwaysVisible ? 'block' : 'none',
                        BorderRadius: size,
                        MozBorderRadius: size,
                        WebkitBorderRadius: size,
                        zIndex: 99
                });

                //set position
                var posCss = (position == 'right') ? { right: '1px' } : { left: '1px' };
                rail.css(posCss);
                bar.css(posCss);

                //wrap it
                me.wrap(wrapper);

                //append to parent div
                me.parent().append(bar);
                me.parent().append(rail);

                //make it draggable
                bar.draggable({ 
                    axis: 'y', 
                    containment: 'parent',
                    start: function() { isDragg = true; },
                    stop: function() { isDragg = false; hideBar(); },
                    drag: function(e) 
                    { 
                        //scroll content
                        scrollContent(0, $(this).position().top, false);
                    }
                });

                //on rail over
                rail.hover(function(){
                    showBar();
                }, function(){
                    hideBar();
                });

                //on bar over
                bar.hover(function(){
                    isOverBar = true;
                }, function(){
                    isOverBar = false;
                });

                //show on parent mouseover
                me.hover(function(){
                    isOverPanel = true;
                    showBar();
                    hideBar();
                }, function(){
                    isOverPanel = false;
                    hideBar();
                });

                var _onWheel = function(e)
                {
                    //use mouse wheel only when mouse is over
                    if (!isOverPanel) { return; }

                    var e = e || window.event;

                    var delta = 0;
                    if (e.wheelDelta) { delta = -e.wheelDelta/120; }
                    if (e.detail) { delta = e.detail / 3; }

                    //scroll content
                    scrollContent(0, delta, true);

                    //stop window scroll
                    if (e.preventDefault) { e.preventDefault(); }
                    e.returnValue = false;
                }

                var scrollContent = function(x, y, isWheel)
                {
                    var delta = y;

                    if (isWheel)
                    {
                        //move bar with mouse wheel
                        delta = bar.position().top + y * wheelStep;

                        //move bar, make sure it doesn't go out
                        delta = Math.max(delta, 0);
                        var maxTop = me.outerHeight() - bar.outerHeight();
                        delta = Math.min(delta, maxTop);

                        //scroll the scrollbar
                        bar.css({ top: delta + 'px' });
                    }

                    //calculate actual scroll amount
                    percentScroll = parseInt(bar.position().top) / (me.outerHeight() - bar.outerHeight());
                    delta = percentScroll * (me[0].scrollHeight - me.outerHeight());

                    //scroll content
                    me.scrollTop(delta);

                    //ensure bar is visible
                    showBar();
                }

                var attachWheel = function()
                {
                    if (window.addEventListener)
                    {
                        this.addEventListener('DOMMouseScroll', _onWheel, false );
                        this.addEventListener('mousewheel', _onWheel, false );
                    } 
                    else
                    {
                        document.attachEvent("onmousewheel", _onWheel)
                    }
                }

                //attach scroll events
                attachWheel();

                var getBarHeight = function()
                {
                    //calculate scrollbar height and make sure it is not too small
                    barHeight = Math.max((me.outerHeight() / me[0].scrollHeight) * me.outerHeight(), minBarHeight);
                    bar.css({ height: barHeight + 'px' });
                }

                //set up initial height
                getBarHeight();

                var showBar = function()
                {
                    //recalculate bar height
                    getBarHeight();
                    clearTimeout(queueHide);

                    //show only when required
                    if(barHeight >= me.outerHeight()) {
                        return;
                    }
                    bar.fadeIn('fast');
                }

                var hideBar = function()
                {
                    //only hide when options allow it
                    if (!alwaysVisible)
                    {
                        queueHide = setTimeout(function(){
                            if (!isOverBar && !isDragg) { bar.fadeOut('slow'); }
                        }, 1000);
                    }
                }

            });

            //maintain chainability
            return this;
        }
    });

    jQuery.fn.extend({
        slimscroll: jQuery.fn.slimScroll
    });

})(jQuery);


//invalid name call
              $('#chatlist').slimscroll({
                  color: '#00f',
                  size: '10px',
                  width: '50px',
                  height: '150px'                  
              });
</script>

  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
  • 2011年8月19日-这里是对Stephen P.帖子的更新,它有一个样式化的滚动条-迈克。。。您通常将溢出设置为“无”,然后
CSS:

<!DOCTYPE html>
<html>
<body>
    <div id="chatlist" class="mousescroll gridcontainer">
        <ul>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>

        </ul>
    </div>
</body>
</html>
<style>
    .gridcontainer {
      position: absolute;
      top: 0; bottom: 0; left: 0; right: 0;
      overflow: auto;
    }
        div#chatlist {
        /**width: 50px;
        height: 540px;**/
        border: 1px solid black;
    }
    div.mousescroll {
        overflow: hidden;
    }
    div.mousescroll:hover {
        overflow-y: scroll;
    }
    ul {
        list-style-type: none;
        padding-left: 10px;
        padding-right: 10px;
    }
    .slimScrollDiv { border: 1px solid #ccc; margin:10px; }
    li {
        margin-bottom:20px;
    }
</style>
<script>
(function($) {

    jQuery.fn.extend({
        slimScroll: function(o) {

            var ops = o;
            //do it for every element that matches selector
            this.each(function(){

            var isOverPanel, isOverBar, isDragg, queueHide, barHeight,
                divS = '<div></div>',
                minBarHeight = 30,
                wheelStep = 30,
                o = ops || {},
                cwidth = o.width || 'auto',
                cheight = o.height || '250px',
                size = o.size || '7px',
                color = o.color || '#000',
                position = o.position || 'right',
                opacity = o.opacity || .4,
                alwaysVisible = o.alwaysVisible === true;

                //used in event handlers and for better minification
                var me = $(this);

                //wrap content
                var wrapper = $(divS).css({
                    position: 'relative',
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                }).attr({ 'class': 'slimScrollDiv' });

                //update style for the div
                me.css({
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                });

                //create scrollbar rail
                var rail  = $(divS).css({
                    width: '15px',
                    height: '100%',
                    position: 'absolute',
                    top: 0
                });

                //create scrollbar
                var bar = $(divS).attr({ 
                    'class': 'slimScrollBar ', 
                    style: 'border-radius: ' + size 
                    }).css({
                        background: color,
                        width: size,
                        position: 'absolute',
                        top: 0,
                        opacity: opacity,
                        display: alwaysVisible ? 'block' : 'none',
                        BorderRadius: size,
                        MozBorderRadius: size,
                        WebkitBorderRadius: size,
                        zIndex: 99
                });

                //set position
                var posCss = (position == 'right') ? { right: '1px' } : { left: '1px' };
                rail.css(posCss);
                bar.css(posCss);

                //wrap it
                me.wrap(wrapper);

                //append to parent div
                me.parent().append(bar);
                me.parent().append(rail);

                //make it draggable
                bar.draggable({ 
                    axis: 'y', 
                    containment: 'parent',
                    start: function() { isDragg = true; },
                    stop: function() { isDragg = false; hideBar(); },
                    drag: function(e) 
                    { 
                        //scroll content
                        scrollContent(0, $(this).position().top, false);
                    }
                });

                //on rail over
                rail.hover(function(){
                    showBar();
                }, function(){
                    hideBar();
                });

                //on bar over
                bar.hover(function(){
                    isOverBar = true;
                }, function(){
                    isOverBar = false;
                });

                //show on parent mouseover
                me.hover(function(){
                    isOverPanel = true;
                    showBar();
                    hideBar();
                }, function(){
                    isOverPanel = false;
                    hideBar();
                });

                var _onWheel = function(e)
                {
                    //use mouse wheel only when mouse is over
                    if (!isOverPanel) { return; }

                    var e = e || window.event;

                    var delta = 0;
                    if (e.wheelDelta) { delta = -e.wheelDelta/120; }
                    if (e.detail) { delta = e.detail / 3; }

                    //scroll content
                    scrollContent(0, delta, true);

                    //stop window scroll
                    if (e.preventDefault) { e.preventDefault(); }
                    e.returnValue = false;
                }

                var scrollContent = function(x, y, isWheel)
                {
                    var delta = y;

                    if (isWheel)
                    {
                        //move bar with mouse wheel
                        delta = bar.position().top + y * wheelStep;

                        //move bar, make sure it doesn't go out
                        delta = Math.max(delta, 0);
                        var maxTop = me.outerHeight() - bar.outerHeight();
                        delta = Math.min(delta, maxTop);

                        //scroll the scrollbar
                        bar.css({ top: delta + 'px' });
                    }

                    //calculate actual scroll amount
                    percentScroll = parseInt(bar.position().top) / (me.outerHeight() - bar.outerHeight());
                    delta = percentScroll * (me[0].scrollHeight - me.outerHeight());

                    //scroll content
                    me.scrollTop(delta);

                    //ensure bar is visible
                    showBar();
                }

                var attachWheel = function()
                {
                    if (window.addEventListener)
                    {
                        this.addEventListener('DOMMouseScroll', _onWheel, false );
                        this.addEventListener('mousewheel', _onWheel, false );
                    } 
                    else
                    {
                        document.attachEvent("onmousewheel", _onWheel)
                    }
                }

                //attach scroll events
                attachWheel();

                var getBarHeight = function()
                {
                    //calculate scrollbar height and make sure it is not too small
                    barHeight = Math.max((me.outerHeight() / me[0].scrollHeight) * me.outerHeight(), minBarHeight);
                    bar.css({ height: barHeight + 'px' });
                }

                //set up initial height
                getBarHeight();

                var showBar = function()
                {
                    //recalculate bar height
                    getBarHeight();
                    clearTimeout(queueHide);

                    //show only when required
                    if(barHeight >= me.outerHeight()) {
                        return;
                    }
                    bar.fadeIn('fast');
                }

                var hideBar = function()
                {
                    //only hide when options allow it
                    if (!alwaysVisible)
                    {
                        queueHide = setTimeout(function(){
                            if (!isOverBar && !isDragg) { bar.fadeOut('slow'); }
                        }, 1000);
                    }
                }

            });

            //maintain chainability
            return this;
        }
    });

    jQuery.fn.extend({
        slimscroll: jQuery.fn.slimScroll
    });

})(jQuery);


//invalid name call
              $('#chatlist').slimscroll({
                  color: '#00f',
                  size: '10px',
                  width: '50px',
                  height: '150px'                  
              });
</script>

.gridcontainer{
位置:绝对位置;
顶部:0;底部:0;左侧:0;右侧:0;
溢出:自动;
}
聊天室{
/**宽度:50px;
高度:540px**/
边框:1px纯黑;
}
滑鼠卷{
溢出:隐藏;
}
分区鼠标滚动:悬停{
溢出y:滚动;
}
保险商实验室{
列表样式类型:无;
左侧填充:10px;
右边填充:10px;
}
.slimScrollDiv{边框:1px实心#ccc;边距:10px;}
李{
边缘底部:20px;
}
Javascript:

<!DOCTYPE html>
<html>
<body>
    <div id="chatlist" class="mousescroll gridcontainer">
        <ul>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>
            <li>Aug 19, 2011 - Here is an update to Stephen P.'s post to have a styled scroll bar.  -Mike ... You set the overflow to none normally and ...</li>

        </ul>
    </div>
</body>
</html>
<style>
    .gridcontainer {
      position: absolute;
      top: 0; bottom: 0; left: 0; right: 0;
      overflow: auto;
    }
        div#chatlist {
        /**width: 50px;
        height: 540px;**/
        border: 1px solid black;
    }
    div.mousescroll {
        overflow: hidden;
    }
    div.mousescroll:hover {
        overflow-y: scroll;
    }
    ul {
        list-style-type: none;
        padding-left: 10px;
        padding-right: 10px;
    }
    .slimScrollDiv { border: 1px solid #ccc; margin:10px; }
    li {
        margin-bottom:20px;
    }
</style>
<script>
(function($) {

    jQuery.fn.extend({
        slimScroll: function(o) {

            var ops = o;
            //do it for every element that matches selector
            this.each(function(){

            var isOverPanel, isOverBar, isDragg, queueHide, barHeight,
                divS = '<div></div>',
                minBarHeight = 30,
                wheelStep = 30,
                o = ops || {},
                cwidth = o.width || 'auto',
                cheight = o.height || '250px',
                size = o.size || '7px',
                color = o.color || '#000',
                position = o.position || 'right',
                opacity = o.opacity || .4,
                alwaysVisible = o.alwaysVisible === true;

                //used in event handlers and for better minification
                var me = $(this);

                //wrap content
                var wrapper = $(divS).css({
                    position: 'relative',
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                }).attr({ 'class': 'slimScrollDiv' });

                //update style for the div
                me.css({
                    overflow: 'hidden',
                    width: cwidth,
                    height: cheight
                });

                //create scrollbar rail
                var rail  = $(divS).css({
                    width: '15px',
                    height: '100%',
                    position: 'absolute',
                    top: 0
                });

                //create scrollbar
                var bar = $(divS).attr({ 
                    'class': 'slimScrollBar ', 
                    style: 'border-radius: ' + size 
                    }).css({
                        background: color,
                        width: size,
                        position: 'absolute',
                        top: 0,
                        opacity: opacity,
                        display: alwaysVisible ? 'block' : 'none',
                        BorderRadius: size,
                        MozBorderRadius: size,
                        WebkitBorderRadius: size,
                        zIndex: 99
                });

                //set position
                var posCss = (position == 'right') ? { right: '1px' } : { left: '1px' };
                rail.css(posCss);
                bar.css(posCss);

                //wrap it
                me.wrap(wrapper);

                //append to parent div
                me.parent().append(bar);
                me.parent().append(rail);

                //make it draggable
                bar.draggable({ 
                    axis: 'y', 
                    containment: 'parent',
                    start: function() { isDragg = true; },
                    stop: function() { isDragg = false; hideBar(); },
                    drag: function(e) 
                    { 
                        //scroll content
                        scrollContent(0, $(this).position().top, false);
                    }
                });

                //on rail over
                rail.hover(function(){
                    showBar();
                }, function(){
                    hideBar();
                });

                //on bar over
                bar.hover(function(){
                    isOverBar = true;
                }, function(){
                    isOverBar = false;
                });

                //show on parent mouseover
                me.hover(function(){
                    isOverPanel = true;
                    showBar();
                    hideBar();
                }, function(){
                    isOverPanel = false;
                    hideBar();
                });

                var _onWheel = function(e)
                {
                    //use mouse wheel only when mouse is over
                    if (!isOverPanel) { return; }

                    var e = e || window.event;

                    var delta = 0;
                    if (e.wheelDelta) { delta = -e.wheelDelta/120; }
                    if (e.detail) { delta = e.detail / 3; }

                    //scroll content
                    scrollContent(0, delta, true);

                    //stop window scroll
                    if (e.preventDefault) { e.preventDefault(); }
                    e.returnValue = false;
                }

                var scrollContent = function(x, y, isWheel)
                {
                    var delta = y;

                    if (isWheel)
                    {
                        //move bar with mouse wheel
                        delta = bar.position().top + y * wheelStep;

                        //move bar, make sure it doesn't go out
                        delta = Math.max(delta, 0);
                        var maxTop = me.outerHeight() - bar.outerHeight();
                        delta = Math.min(delta, maxTop);

                        //scroll the scrollbar
                        bar.css({ top: delta + 'px' });
                    }

                    //calculate actual scroll amount
                    percentScroll = parseInt(bar.position().top) / (me.outerHeight() - bar.outerHeight());
                    delta = percentScroll * (me[0].scrollHeight - me.outerHeight());

                    //scroll content
                    me.scrollTop(delta);

                    //ensure bar is visible
                    showBar();
                }

                var attachWheel = function()
                {
                    if (window.addEventListener)
                    {
                        this.addEventListener('DOMMouseScroll', _onWheel, false );
                        this.addEventListener('mousewheel', _onWheel, false );
                    } 
                    else
                    {
                        document.attachEvent("onmousewheel", _onWheel)
                    }
                }

                //attach scroll events
                attachWheel();

                var getBarHeight = function()
                {
                    //calculate scrollbar height and make sure it is not too small
                    barHeight = Math.max((me.outerHeight() / me[0].scrollHeight) * me.outerHeight(), minBarHeight);
                    bar.css({ height: barHeight + 'px' });
                }

                //set up initial height
                getBarHeight();

                var showBar = function()
                {
                    //recalculate bar height
                    getBarHeight();
                    clearTimeout(queueHide);

                    //show only when required
                    if(barHeight >= me.outerHeight()) {
                        return;
                    }
                    bar.fadeIn('fast');
                }

                var hideBar = function()
                {
                    //only hide when options allow it
                    if (!alwaysVisible)
                    {
                        queueHide = setTimeout(function(){
                            if (!isOverBar && !isDragg) { bar.fadeOut('slow'); }
                        }, 1000);
                    }
                }

            });

            //maintain chainability
            return this;
        }
    });

    jQuery.fn.extend({
        slimscroll: jQuery.fn.slimScroll
    });

})(jQuery);


//invalid name call
              $('#chatlist').slimscroll({
                  color: '#00f',
                  size: '10px',
                  width: '50px',
                  height: '150px'                  
              });
</script>

(函数($){
jQuery.fn.extend({
滚动条:功能(o){
var-ops=o;
//对与选择器匹配的每个元素执行此操作
这个。每个(函数(){
变量isOverPanel、isOverBar、isDragg、队列隐藏、条形高度、,
divS=“”,
minBarHeight=30,
车轮踏板=30,
o=ops |{},
cwidth=o.width | |“自动”,
cheight=o.高度| |“250px”,
尺寸=o.size | |“7px”,
color=o.color | |‘#000’,
位置=o。位置| |“右”,
不透明度=o.opacity | |.4,
alwaysVisible=o.alwaysVisible==true;
//在事件处理程序中使用,以便更好地缩小
var me=$(此);
//包装内容
var包装器=$(divS).css({
位置:'相对',
溢出:“隐藏”,
宽度:cwidth,
身高:切特
}).attr({'class':'slimScrollDiv'});
//更新div的样式
me.css({
溢出:'